PHP方法调用报告关于它是未定义方法的错误 [英] PHP method call reports error about it being undefined method

查看:522
本文介绍了PHP方法调用报告关于它是未定义方法的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我的类是正确的,但当我尝试回显类的输出,我得到一个错误在第28行:线echo'你的全名....是第28行。任何帮助将是很好的

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() . '.';

?>

这是我创建函数 retrieve_full_name

public function __retrieve_full_name() {
    $fullname = $this->firstname . ' . ' . $this->lastname;
    return $fullname;
}/* This ends the Full Name Function*/

/ p>

the error I get is


致命错误:调用未定义的方法stdClass :: retrieve_full_name()在/home/mjcrawle/processlogin2.php第28行

Fatal error: Call to undefined method stdClass::retrieve_full_name() in /home/mjcrawle/processlogin2.php on line 28


推荐答案

您的函数名为 __ retrieve_full_name 调用 retrieve_full_name 。注意缺少的下划线。

your function is called __retrieve_full_name, but you call retrieve_full_name. notice the missing underscores.

双下划线通常是php内部/魔术函数的前缀,我建议不要在函数名中使用它们。

double underscores are usually the prefix for php internal/magic functions, i would advise against using them in your function names.

这篇关于PHP方法调用报告关于它是未定义方法的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆