Skip to content

Instantly share code, notes, and snippets.

@panfeng
Last active December 15, 2015 19:29
Show Gist options
  • Save panfeng/5312194 to your computer and use it in GitHub Desktop.
Save panfeng/5312194 to your computer and use it in GitHub Desktop.
<?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