php变量空出错,php - PHP使用代码[重复]获取“未定义变量和”空属性“错误 - 堆栈内存溢出...

我把这个错误减少到最小的代码量,而且它很小,我真的觉得这里很蠢。

我有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

我知道这是一个简单的答案,我搜索并搜索每个帖子都有错误信息。 我甚至尝试将文本的赋值移动到构造函数中的变量,它无法正常工作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值