Last active
December 15, 2015 19:29
-
-
Save panfeng/5312194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pre_print_r($var){ | |
echo "<pre>"; | |
print_r($var); | |
echo "</pre>"; | |
} | |
class Obj1 { | |
public function __call($method,$arg){ | |
return $this; }} | |
class Obj2 { | |
public function __call($method,$arg){ | |
$this->$method = $arg[0]; | |
return $this; }} | |
$obj1 = new Obj1; | |
$obj1->name = "panfeng"; | |
$obj1->age(23) | |
->sex("male") | |
->github_account("panfeng") | |
->twitter_account("NULL"); | |
pre_print_r($obj1); | |
$obj2 = new Obj2; | |
//为什么赋值的方法也可以用 | |
$obj2->name = "panfeng"; | |
$obj2->age(23) | |
->sex("male") | |
->github_account("panfeng") | |
->twitter_account("NULL"); | |
pre_print_r($obj2); | |
/* | |
* 输出为 | |
Obj1 Object | |
( | |
[name] => panfeng | |
) | |
Obj2 Object | |
( | |
[name] => panfeng | |
[age] => 23 | |
[sex] => male | |
[github_account] => panfeng | |
[twitter_account] => NULL | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment