You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
344 B

3 years ago
  1. <?php
  2. class clsA{
  3. public $a = 'hello';
  4. private $b;
  5. public function __get($name)
  6. {
  7. echo "获取{$name}失败,{$name}未定义".'<br>';
  8. }
  9. }
  10. $obj = new clsA();
  11. $obj -> a = 'world';
  12. echo $obj -> b; //b未定义,当b被调用时,自动调用了__get,自动传入key
  13. ?>