PHP 方法调用报告有关该方法未定义的错误
我相信我的类是正确的,但是当我尝试回显类的输出时,我在第 28 行收到错误:“ echo '你的全名 ....” 行是第 28 行。任何帮助都会很好
<?php
echo 'Your full name is ' . $person->retrieve_full_name() . '.';
?>
这是在哪里我创建了函数“retrieve_full_name”,
public function __retrieve_full_name() {
$fullname = $this->firstname . ' . ' . $this->lastname;
return $fullname;
}/* This ends the Full Name Function*/
我得到的错误是
致命错误:在第 28 行调用 /home/mjcrawle/processlogin2.php 中未定义的方法 stdClass::retrieve_full_name()
I believe my class is correct but when I try to echo the output of the class I get an error on line 28: the line " echo 'Your full name ...." is line 28. Any help would be nice
<?php
echo 'Your full name is ' . $person->retrieve_full_name() . '.';
?>
This is where I created the function "retrieve_full_name"
public function __retrieve_full_name() {
$fullname = $this->firstname . ' . ' . $this->lastname;
return $fullname;
}/* This ends the Full Name Function*/
the error I get is
Fatal error: Call to undefined method stdClass::retrieve_full_name() in /home/mjcrawle/processlogin2.php on line 28
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的函数名为
__retrieve_full_name
,但您调用retrieve_full_name
。注意缺少的下划线。双下划线通常是 php 内部/魔术函数的前缀,我建议不要在函数名称中使用它们。
your function is called
__retrieve_full_name
, but you callretrieve_full_name
. notice the missing underscores.double underscores are usually the prefix for php internal/magic functions, i would advise against using them in your function names.
您立即出现的错误是由于您使用错误的名称调用了方法。并且:
retrieveFullName()
。Your immediate error is due to the fact that you call your method by the wrong name. And:
retrieveFullName()
.