首页 > Web开发 > 详细

php 给对象动态增加属性

时间:2017-11-12 17:52:15      阅读:334      评论:0      收藏:0      [点我收藏+]
    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 给对象动态增加属性

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!