脚本宝典收集整理的这篇文章主要介绍了在php中返回对象,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
class User{ public $uid; public $name; public $status; } function GetUserInfo($uid) { // Query DB $userObj = new User(); // convert the result into the User object. var_dump($userObj); return $userObj; } // In another file I call the above function. .... $newuser = GetUserInfo($uid); VAR_dump($newuser);
这里有什么问题,我无法理解.本质上,函数GetUserInfo()中的var_dump()工作正常.调用GetUserInfo()之后的var_dump()不起作用.
<PRe> <?PHP class User{ public $uid; public $name; public $status; } function GetUserInfo($uid) { $userObj = new User(); $userObj->uid=$uid; $userObj->name='zaf'; $userObj->status='guru'; return $userObj; } $newuser = GetUserInfo(1); var_dump($newuser); ?> </pre> object(User)#1 (3) { ["uid"]=> int(1) ["name"]=> string(3) "zaf" ["status"]=> string(4) "guru" }
以上是脚本宝典为你收集整理的在php中返回对象全部内容,希望文章能够帮你解决在php中返回对象所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。