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.

17 lines
450 B

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