php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.9k stars 953 forks source link

nginx php-fpm running error #19

Closed abc0707 closed 9 years ago

abc0707 commented 9 years ago

Hello, after install and setup properly I got this error:

FastCGI sent in stderr: "PHP message: PHP Fatal error: Call to a member function isEnabled() on a non-object in /var/www/vendor/longman/telegram-bot/src/Commands/HelpCommand.php

could you please help me this that?

MBoretto commented 9 years ago

are you using 0.11?

abc0707 commented 9 years ago

Hello MBoretto, I tried composer install require... then I got that problem then I tried composer updatte .... problem solved :)

Thanks

abc0707 commented 9 years ago

yeah... seem like 0.1.1 has problem (composer install), when i tried 0.0.7 (clone from git), it works just fine. I still receive: PHP Fatal error: Call to a member function isEnabled() on a non-object in after using 0.1.1

Doranku commented 9 years ago

Issue is not related to nginx and still persists in 0.12

abc0707 commented 9 years ago

confirmed... I tried with apache, still have this problem On Aug 8, 2015 11:10 PM, "Doranku" notifications@github.com wrote:

Issue is not related to nginx and still persists in 0.12

— Reply to this email directly or view it on GitHub https://github.com/akalongman/php-telegram-bot/issues/19#issuecomment-128993790 .

Doranku commented 9 years ago

The problem there is a non object in the getCommandsLists ('leftchatparticipant' => false)

To prevent this from having a working bot, the symptom can be avoided with following patch.

--- a/src/Commands/HelpCommand.php
+++ b/src/Commands/HelpCommand.php
@@ -37,6 +37,10 @@ class HelpCommand extends Command
             $msg = 'GeoBot v. ' . $this->telegram->getVersion() . "\n\n";
             $msg .= 'Commands List:' . "\n";
             foreach ($commands as $command) {
+               if(!is_object($command))
+               {
+                       continue;
+               }
                 if (!$command->isEnabled()) {
                     continue;
                 }

Or by removing src/Commands/LeftChatParticipantCommand.php. But the real solve is having the getCommandsList method in Telegram check whether the getCommandClass returned a Command object.

MBoretto commented 9 years ago

I've pull a commit that fix the help command. Just wait the merge or get the code from my repository. On 8 Aug 2015 20:45, "Doranku" notifications@github.com wrote:

The problem there is a non object in the getCommandsLists ('leftchatparticipant' => false)

To prevent this from having a working bot, the symptom can be avoided with following patch.

--- a/src/Commands/HelpCommand.php +++ b/src/Commands/HelpCommand.php @@ -37,6 +37,10 @@ class HelpCommand extends Command $msg = 'GeoBot v. ' . $this->telegram->getVersion() . "\n\n"; $msg .= 'Commands List:' . "\n"; foreach ($commands as $command) {

  • if(!is_object($command))
  • {
  • continue;
  • } if (!$command->isEnabled()) { continue; }

Or by removing src/Commands/LeftChatParticipantCommand.php. But the real solve is having the getCommandsList method in Telegram check whether the getCommandClass returned a Command object.

— Reply to this email directly or view it on GitHub https://github.com/akalongman/php-telegram-bot/issues/19#issuecomment-129033798 .

Doranku commented 9 years ago

That is a "lazy way" patch :) I meant fix the source of the problem:

--- a/src/Telegram.php
+++ b/src/Telegram.php
@@ -193,6 +193,10 @@ class Telegram
             if (substr($name, -11, 11) === 'Command.php') {
                 $name = strtolower(str_replace('Command.php', '', $name));
                 $commands[$name] = $this->getCommandClass($name);
+               if(!($commands[$name] instanceof \Longman\TelegramBot\Command))
+               {
+                       unset($commands[$name]);
+               }
             }
         }

@@ -209,7 +213,11 @@ class Telegram
                     $name = $fileInfo->getFilename();
                     if (substr($name, -11, 11) === 'Command.php') {
                         $name = strtolower(str_replace('Command.php', '', $name));
                         $commands[$name] = $this->getCommandClass($name);
+                       if(!($commands[$name] instanceof \Longman\TelegramBot\Command))
+                       {
+                               unset($commands[$name]);
+                       }
                     }
                 }
             }
MBoretto commented 9 years ago

Commits has been merged