php代码
<?php function A($class){ if(isset($GLOBALS[$class])){ if(is_object($GLOBALS[$class])){ return $GLOBALS[$class]; } } return $GLOBALS[$class] = new $class(); } class MyClass{ public function getStr(){ return "hh"; } public function getStr1(){ return "cc"; } public function getJson(){ return json_encode(array("name"=>"你好")); } public function getAll(){ $str1 = A("MyClass")->getStr(); $str2 = A("MyClass")->getStr1(); $json = A("MyClass")->getJson(); return $str1.$str2." ".$json; } } echo A("MyClass")->getAll();