我把这个错误减少到最小的代码量,而且它很小,我真的觉得这里很蠢。
我有2个文件class1.php:
1 <?php
2 class insertText{
3 //properties
4 protected $paragraph1='
this is a test paragraph
';5 protected $bigHeader='
header1';
6 protected $textArray;
7
8 public function __construct () {
9 $this->$textArray = array($this->$bigHeader1, $this->$paragraph1);
10 }
11 public function getText(){
12 return $this->$textArray;
13 }
14 }
15 ?>
和test.php:
1 <?php
2 include './class1.php';
3 echo "Begin\n";
4
5 $filler = new insertText();
6 echo $filler->getText();
7
8 echo "end\n";
9 ?>
当我运行:$ php text.php
Begin
PHP Notice: Undefined variable: bigHeader1 in class1.php on line 9
PHP Fatal error: Cannot access empty property in class1.php on line 9
我知道这是一个简单的答案,我搜索并搜索每个帖子都有错误信息。 我甚至尝试将文本的赋值移动到构造函数中的变量,它无法正常工作。