PHP 类;通知: Undefined property error

标签 php function class undefined

在我提出问题之前,我想说我搜索过这个问题,并且其他答案都没有帮助......

基本上,在我的类DemoClass中,我有4个函数,并且它们都是“未定义的属性”

我的错误:

Notice: Undefined property: DemoClass::$function in /home/content/92/10270192/html/class.php on line 46

注意:第 46 行是我执行 $demoClass->function... 的地方

我有一个典型的类(class)设置:

class DemoClass {
    public function __construct () {
        // stuff that works and gets called
    }
    public function testFunct () {
        // one that is an "undefined property"
    }
}

我正常访问类(class):

$testClass = new DemoClass();
var_dump(testClass->testFunct); // this is what is on line 46
// ^^^ This also gives me NULL, because its undefined (? i guess...)

我以前从未遇到过这个问题,有什么建议吗?谢谢!

最佳答案

调用函数时需要括号。将其更改为 $testClass->testFunct()

关于PHP 类;通知: Undefined property error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21083808/

相关文章:

c++ - 获取类变量的错误值

php - 如何将 javascript 日期转换为 Carbon Date?

php - 找不到类 'Aws\Common\Aws' cakephp

php - 如何在javascript中动态调用php函数

c++ - 使用 map 时 WinAPI WndProc 静默失败

java - 创建一个无法创建其对象的类

php - 从mysql生成统计信息

php - Laravel 实时统计登录用户数

php - 使用链接中的查询删除mysql数据库中的记录

C - 通过函数参数传递结构