【发布时间】:2021-01-06 10:24:36
【问题描述】:
我有类 OnboardingConversation,我从命名空间 BotMan\BotMan\Messages\Conversations\Conversation 调用方法 say
namespace PanObed\Conversations;
use BotMan\BotMan\Messages\Conversations\Conversation;
class OnboardingConversation extends Conversation{
protected $name;
public function __construct() {
return $this->run();
}
public function run() {
$this->say("Say hello");
}
}
还有类 BotMan\BotMan\Messages\Conversations\Conversation
namespace BotMan\BotMan\Messages\Conversations;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Interfaces\ShouldQueue;
use BotMan\BotMan\Messages\Attachments\Audio;
use BotMan\BotMan\Messages\Attachments\Contact;
use BotMan\BotMan\Messages\Attachments\File;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Attachments\Location;
use BotMan\BotMan\Messages\Attachments\Video;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Messages\Outgoing\Question;
use Closure;
use Illuminate\Support\Collection;
use Spatie\Macroable\Macroable;
abstract class Conversation
{
use Macroable;
/**
* @var BotMan
*/
protected $bot;
public function say($message, $additionalParameters = [])
{
$this->bot->reply($message, $additionalParameters);
return $this;
}
}
但是有一个问题,当我调用 new OnboardingConversation 时出现此错误:
<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function reply() on null in C:\xampp\htdocs\panobed\bot\vendor\botman\botman\src\Messages\Conversations\Conversation.php:205
Stack trace:
#0 C:\xampp\htdocs\panobed\bot\class\Conversations\OnboardingConversation.php(32): BotMan\BotMan\Messages\Conversations\Conversation->say('Test')
#1 C:\xampp\htdocs\panobed\bot\class\Conversations\OnboardingConversation.php(23): PanObed\Conversations\OnboardingConversation->run()
#2 C:\xampp\htdocs\panobed\bot\index.php(27): PanObed\Conversations\OnboardingConversation->__construct()
#3 [internal function]: {closure}(Object(BotMan\BotMan\BotMan))
#4 C:\xampp\htdocs\panobed\bot\vendor\botman\botman\src\BotMan.php(495): call_user_func_array(Object(Closure), Array)
#5 C:\xampp\htdocs\panobed\bot\vendor\botman\botman\src\BotMan.php(425): BotMan\BotMan\BotMan->callMatchingMessages()
#6 C:\xampp\htdocs\panobed\bot\index.php(32): BotMan\BotMan\BotMan->listen()
#7 {main}
thrown in <b>C:\xampp\htdocs\panobed\bot\vendor\botman\botman\src\Messages\Conversations\Conversation.php</b> on line <b>205</b><br />
如果我不使用命名空间PanObed\Conversations,代码是可以的。那么你能告诉我,我做错了什么吗?
谢谢
【问题讨论】:
标签: php class methods abstract