<?php
//
//
//1. __autoload()
function __autoload($classname){
if (isset($classname)){
require_once $classname.'.class.php';
}
}
/* $computer1=new Computer();
$computer1->addList('dalisng',234);
echo $computer1; */
//__call() , , __call() 。
// , ,
$computer2=new Computer();
echo $computer2->name;echo "<br/>";
$computer3=new Computer();
echo $computer3->name;echo "<br/>";
$computer3->name=" ";
echo '$computer3->name:'.$computer3->name;echo "<br/>";
echo '$computer2->name:'.$computer2->name;echo "<br/>";
echo "<hr/>";
// , , , ,
$computer4=new Computer();
echo '$computer4->name:'.$computer4->name;echo "<br/>";
$computer5=$computer4;
echo '$computer5->name:'.$computer5->name;echo "<br/>";
$computer4->name=" ";
echo '$computer4->name:'.$computer4->name;echo "<br/>";
echo '$computer5->name:'.$computer5->name;echo "<br/>";
echo "<hr/>";
// __clone, , , ,
$computer6=new Computer();
echo '$computer6->name:'.$computer6->name;echo "<br/>";
$computer7=clone $computer6;
echo '$computer7->name:'.$computer7->name;echo "<br/>";
$computer6->name=" ";
echo '$computer6->name:'.$computer6->name;echo "<br/>";
echo '$computer7->name:'.$computer7->name;echo "<br/>";
Computer.class.php
<?php
class Computer{
public $name="1234";
function __construct(){
echo "you are right!";
}
function __call($methodName,$argsList){// ,$argsList
echo $methodName."() !";
echo "<pre>";
print_r($argsList);
echo "</pre>";
}
private function __toString(){ // , echo
echo " !";
}
}
以上、PHPマジックの方法と、単独のインスタンスと接続例についての全面的な説明を行いました。どうぞよろしくお願いします。