码迷,mamicode.com
首页 > Web开发 > 详细

php 给对象动态增加属性

时间:2017-11-12 17:56:17      阅读:508      评论:0      收藏:0      [点我收藏+]

标签:static   span   public   art   ini   repo   alt   hello   isp   

    1. <?php  
    2. error_reporting(-1);  
    3. ini_set(‘display_errors‘,‘on‘);  
    4.   
    5. class A {   
    6.     public $a = ‘hello‘;  
    7.   
    8.     public function add() {  
    9.         $this->b = ‘world‘;  
    10.     }-    
    11.     public static function p() {  
    12.         echo ‘world‘,PHP_EOL;  
    13.     }-    
    14. }  
    15.   
    16. $a = new A;  
    17. $a->add();  
    18. $a->c = ‘test‘;  
    19. $a->p();  
    20.   
    21. var_dump($a); 
      1. world  
      2. object(A)#1 (3) {  
      3.   ["a"]=>  
      4.   string(5) "hello"  
      5.   ["b"]=>  
      6.   string(5) "world"  
      7.   ["c"]=>  
      8.   string(4) "test"  

php 给对象动态增加属性

标签:static   span   public   art   ini   repo   alt   hello   isp   

原文地址:http://www.cnblogs.com/hehexu/p/7822238.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!