0

我对 Php OOP 非常陌生,并且陷入了一个特定问题。我已经搜寻了stackoverflow以尝试找到答案,但不能。我在这个问题上花了一个多小时,准备放弃了。我知道 Php 大师会立即看到我的问题,所以请告诉我为什么这门课不起作用。

 <?php
class tester{
    public $testproperty;
    public function testfunction(){
        $this->$testproperty = 'Nothing';
        return $this->$testproperty;
    }
}
$object = new tester();
echo $object->testfunction();
?>
4

2 回答 2

2
$this->testproperty; //without $
于 2012-06-30T06:13:28.953 回答
1

改变

$this->$testproperty

$this->testproperty

始终首先阅读有关该主题的手册。

于 2012-06-30T06:13:28.913 回答