【关于print_r的一个怪现象】解决方法

WBOY
Release: 2016-06-13 13:43:09
Original
1061 people have browsed it

【关于print_r的一个怪现象】
class ColumnVo extends Vo{
  public $column_id;
  public $column_name = array('label'=>'栏目名称','value'=>'haha');
  .............


}

-------------------------------------------
  if($property=='column_name'){
  print_r($this->$property['value']);
  echo '
';
echo 'Form value is: '.$value.'
';
$this->$property['value'] = $value; 
print_r($this->$property['value']);
echo
';
print_r($this->$property);
}
-----------------输出----------------------
Undefined property: ColumnVoMysql 报错
Form value is: cccccccc
cccccccc
Array ( [label] => 栏目名称 [value] ='haha'> )
-------------------------------------------
第二行输出说明值的却已经赋上去了。 但是打印数组却只打印VO原有的值, [type] => string 这个是VO原来就写死的。

总结:print_r 有点懒加载的味道,我被print_r害惨了。

------解决方案--------------------
语法歧义造成的


你可以改成
$this->{$property}['value']

$this->{$property}['value'] = $value;

……
print_r……

------解决方案--------------------
还是用常规的方法好。不要直接改属性,通过魔术的或者自定义的get,set方法多好。会避免很多问题。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!