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
450 B

<?php
/*
* 重载:重新写类成员,只有当调用类中没有的成员时才会使用
*/
class clsA{
public $a = 'hello';
private $b;
public function __set($key,$val)
{
echo "{$key}未定义, val:{$val}".'<br>';
}
}
$obj = new clsA();
$obj -> a = 'world';
$obj -> b = 'test'; //b未定义,但b被赋值时,自动调用了__set,自动传入b和test
?>