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.

18 lines
494 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <?php
  2. /*
  3. * 重载:重新写类成员,只有当调用类中没有的成员时才会使用
  4. */
  5. //__set(), 未定义或不可访问的
  6. class clsA{
  7. public $a = 'hello';
  8. private $b;
  9. public function __set($key,$val)
  10. {
  11. echo "{$key}未定义, val:{$val}".'<br>';
  12. }
  13. }
  14. $obj = new clsA();
  15. $obj -> a = 'world';
  16. $obj -> b = 'test'; //b未定义,但b被赋值时,自动调用了__set,自动传入b和test
  17. ?>