Closed kovalovme closed 3 years ago
Hello! In the first place, you are just trying to access undefined variable, there are no issues with dynamic calls. And in my opiniot - this is good thing that exception thrown when you try to do so. It prevents a huge amount of logical issues and save you from additional debug hours.
The second thing is that library and PHP by itself naturaly provides you with oneliners to "bypass" undefined variables. I made a small playground for this issue in library tests:
None of these examples work without throwing an Exception
Thats not true actually, the first check will work, as get
method is not throwing exceptions by default. Your whole trigger
method may be simplified to a line:
public static function trigger(Update $update, TeleBot $bot) {
return $update->get('message.text') === 'message';
}
or using chain syntax:
public static function trigger(Update $update, TeleBot $bot) {
return $update->message->text ?? null === 'message';
}
Unable to properly handle update request with empty parameter because of dynamic calls inside TelegramObject class.
I would propose to add
check()
method to the TelegramObject class or cast null on undefined values.Example WeStacks\TeleBot\Objects\Update object (ids and usernames were replaced):
None of these examples work without throwing an Exception:
Exception: