westacks / telebot

Easy way to create Telegram bots in PHP
https://westacks.github.io/telebot/
MIT License
282 stars 44 forks source link

PHP Fatal error #36

Closed kokamvd closed 2 years ago

kokamvd commented 2 years ago
NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class "WeStacks\TeleBot\Traits\get_class" not found in /var/www/vendor/westacks/telebot/src/Traits/HandlesUpdates.php:40

Laravel v8.80.0 (PHP v8.1.1)

Looks like this commit is wrong 76f9607bc96a0cca0ee66126c28bf2b534b52edc

punyflash commented 2 years ago

The PHP have a strange behavior for such syntax. Tested some stuff in sandbox and that's what I discovered:

PHP <= 7.4

<?php

$class = new (get_class(new Exception)));

Gives error:

Parse error: syntax error, unexpected '(' in test.php on line 4

Process exited with code 255.

However, it works for PHP => 8.0.

PHP 8.1

<?php

$class = new get_class(new Exception);

Gives error:

Fatal error: Uncaught Error: Class "get_class" not found in test.php:4
Stack trace:
#0 {main}
  thrown in /in/CPRRi on line 4

Process exited with code 255.

However, it works for PHP <= 8.0.

Fix

In version 2, the kernel object will be reworked, and the issue will be resolved by itself, but for now something like this will fix the issue:

$kernel = get_class($this->kernel);
$this->kernel = new $kernel;

Thanks for contribution!