</pre><pre name= "code" class= "PHP" ><?php date_default_timezone_set ("PRC"); /** * Magic Method 3 Property Overload * 1.
When you assign a value to an inaccessible property, __set () is invoked. * 2.
__get () is invoked when the value of an inaccessible property is read. * 3.
When Isset () and empty () are invoked on an inaccessible property, __isset () is invoked. * 4.
When unset () is invoked on an inaccessible property, __unset () is called/class magictest{public $name;
The Public Function __tostring () {return ' This is the Class magictest.\n '; The Public Function __invoke ($x) {echo ' __invoke called with parameter '. $x.
"\ n"; The Public Function __call ($name, $arguments) {echo "calling". $name. "With parameters:". Implode (', ', $arguments).
"\ n"; The public static function __callstatic ($name, $arguments) {echo "Static calling". $name. "With parameters:". Implode (', ', $arguments).
"\ n"; //Through these two methods you can implement the dynamic object properties Public Function __get ($name) {return "getting".
$name; The Public Function __set ($name, $value) {echo ' Setting the property '. $name. "To value". $value.
"\ n"; } public Function __isset ($name) {echo "__isset invoked\n";
return false; The Public Function __unset ($name) {echo ' Unsetting property '.
$name;
The Public Function __clone () {//Deep copy}} $obj = new Magictest (); Echo $obj->name. "\ n"; The Name property is not present in the object, the read does not exist, the __get method is called $obj->name = "name Value";//The Name property is not present in the object, the setting does not exist, and the __set method is invoked by the Echo ' $obj->name is set? '. Isset ($obj->name). "\ n";//object does not exist Name property, __isset method calls Echo ' $obj->name is empty? '. Empty ($obj->name).
"\ n";//object does not exist Name property, __isset method calls unset ($obj->name);//object does not exist Name property, __unset method call $p 1 = new magictest ();
$p 1->name = "P1"; echo $p 1->name. "
\ n ";
$p 2 = clone $p 1;//deep Copy, if there is write __clone magic, then the __clone method call.
$p 2->name = "P2"; echo $p 1->name. "
\ n "; echo $p 2->name. "
\ n "//can see that P2 does not affect P1; $?>