PHP Magic Method and a comprehensive explanation of independent instances and connected instances _php example

Source: Internet
Author: User
<?php//Magic Method//When containing multiple classes of//1. Magic method for automatically loading classes __autoload () function __autoload ($classname) {if (Isset ($classname)) {require_ Once $classname. '
Class.php ';
}/* $computer 1=new Computer ();
$computer 1->addlist (' Dalisng ', 234); echo $computer 1;
* *//__call () mask the error generated when invoking the method, the __call () method is automatically invoked when we call a nonexistent method.
Independent examples, two examples were established respectively, Non-interference $computer 2=new Computer ();
echo $computer 2->name;echo "<br/>";
$computer 3=new Computer ();
echo $computer 3->name;echo "<br/>";
$computer 3->name= "Big bright";
Echo ' $computer 3->name: '. $computer 3->name;echo "<br/>";

Echo ' $computer 2->name: '. $computer 2->name;echo "<br/>";
echo " 

Computer.class.php

<?php
class computer{public
$name = "1234";
function __construct () {
echo "you are right!";
}

function __call ($methodName, $argsList) {//This method is called automatically when the method does not exist, $argsList is the corresponding parameter
echo $methodName. " () method does not exist! ";
echo "<pre>";
Print_r ($argsList);
echo "</pre>";
}

Private Function __tostring () {///when the user outputs a string that does not exist, the method automatically invokes the Echo object name
echo "I am the object's string!" ";
}
}

The above is a small series for everyone to bring the PHP magic method as well as on independent examples and connected to a full explanation of the case of all the content, I hope that we support cloud Habitat Community ~

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.