【发布时间】:2014-11-20 03:49:14
【问题描述】:
我有一个会话变量$_SESSION["customer"],其中包含客户类的一个对象,该对象具有私有属性,例如名字、姓氏等。可以访问它们,但可以访问公共 getter 和 setter。我不知道如何访问它们并在我的代码中使用它们。
这是$_SESSION["customer"]的var_dump
object(Customer)#4 (13) { ["id":"Customer":private]=> string(4) "1019" ["fname":"Customer":private]=> string(4) "john" ["lname":"Customer":private]=> string(3) "doe" ["dob":"Customer":private]=> string(10) "1999-12-12" ["address1":"Customer":private]=> string(10) "humberwood" ["address2":"Customer":private]=> string(0) "" ["city":"Customer":private]=> string(7) "toronto" ["zip":"Customer":private]=> string(6) "m3a1c6" ["province":"Customer":private]=> string(2) "ON" ["gender":"Customer":private]=> string(1) "0" ["email":"Customer":private]=> string(21) "johndoe@humbermail.ca" ["username":"Customer":private]=> string(6) "humber" ["password":"Customer":private]=> string(6) "humber" }
我尝试使用$username = $_SESSION["customer"]->Customer->getUsername();,但没有成功
【问题讨论】:
-
$username = $_SESSION['customer']->getUsername();
-
根据你得到的异常,这个答案可能是一个帮助stackoverflow.com/a/132197/905214