<? PHP
class mycoach
{
public function the __construct ( $ name, $ Age)
{
$ this-> name = $ name;
$ this-> Age = $ Age;
echo . "upon Melancholy Hill" " \ n- ";
}
public function the __toString ()
{
#echo trigger, returns a string return "Hard and Working Party with CPC and CJ." " \ n- "; } public __debugInfo function () { # method strange, a parsing function does not exist and wherein the array it returns an array # the process must have two parameters #var_dump () method of the trigger return [ 'name' =>
this- $> name, 'Age' => $ this-> Age];
}
public function the __call ( $ funcname, $ myvals)
{
# Trigger timing, when the object calls a method does not exist # first parameter function name, a function of the second parameter --- in the form of an array composed var_dump ( $ funcname, $ myvals); } } $ CPC = new new mycoach ( ' Chenpei Chang ', 21 is); echo $ CPC; $ CPC-> wenheiwa (); $ CPC-> saiwa ([ "0" => [ "name" => "CPC", "Age" => 22 is], ". 1" => [ "name" => "CJ","age"=>20]]);
输出结果:
upon melancholy hill #实例化时调用了__construct()方法
working hard and party with cpc and cj #打印对象时调用了__toString方法
string(8) "wenheiwa" #对象调用了不存在的方法wenheiwa()执行了__call方法,由于函数没有参数,因此打印空
array(0) {
}
string(5) "saiwa" #对象调用了不存在的方法saiwa()执行了__call方法,由于函数有参数,因此打印参数----其形式为数组
array(1) {
[0]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "cpc"
["age"]=>
int(22)
}
[1]=>
array(2) {
["name"]=>
string(2) "cj"
["age"]=>
int(20)
}
}
}