Skip to content

$bot->on($fn) doesn't execute $event #511

@codeninja-ru

Description

@codeninja-ru

Bug

The documentation says:

If second closure will return true (or if you are passed null instead of closure), first one will be executed.

Api/src/Client.php

Lines 129 to 143 in a8edf2e

/**
* Use this method to add an event.
* If second closure will return true (or if you are passed null instead of closure), first one will be executed.
*
* @param \Closure $event
* @param \Closure|null $checker
*
* @return \TelegramBot\Api\Client
*/
public function on(Closure $event, ?Closure $checker = null)
{
$this->events->add($event, $checker);
return $this;
}

I passed null as the second parameter.

$bot = new \TelegramBot\Api\Client("token");
$bot->on(function($update) {
  // expected to be executed, but it's not
  var_dump(1);
});
$offset = 0;
while (true) {
    $updates = $bot->getUpdates($offset);
    $bot->handle($updates);
    if (count($updates) > 0) {
        $offset = end($updates)->getUpdateId() + 1;
    }
    sleep(5);
}

The $event is never executed.

Expected

The $event expected to be executed when the second parameter is null or absent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions