PHP object-oriented-Some Rubik's Cube method ____php

Source: Internet
Author: User
</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; $?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.