Message can be NULL and it crashes in AbstractCommand::isApplicable()
Closed this issue · 1 comments
danaki commented
Somehow, I don't know why (I've just edited a previous message in Telegram window, not sure why), I've got an update like this:
object(TelegramBot\Api\Types\Update)#583 (4) {
["updateId":protected]=>
int(74300160)
["message":protected]=>
NULL
["inlineQuery":protected]=>
NULL
["chosenInlineResult":protected]=>
NULL
}
it has no message attached. This leads to crash on telegram:updates command:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Argument 1 passed to BoShurik\TelegramBotBundle\Telegram\Command\AbstractCommand::isApplicable() must be an instance of TelegramBot\Api\Types\Message, null gi
ven, called in /www/pokeroff.dev/vendor/boshurik/telegram-bot-bundle/EventListener/CommandListener.php on line 40
it appears from PHP docs that "To specify a type declaration, the type name should be added before the parameter name. The declaration can be made to accept NULL values if the default value of the parameter is set to NULL.", then if I update the declaration of isApplicable from:
public function isApplicable(Message $message)
to
public function isApplicable(Message $message = NULL)
the issue is gone.
danaki commented
PHP 5.6.25