[英]PHP - How to Retrieve a Value from from an Object
I've been pulling my hair out on this one, including reviewing questions here (like this one for instance: Read var_dump data with PHP ) but I'm just not getting it. 我一直在努力解决这一问题,包括在此处复习问题(例如,类似问题: 使用PHP读取var_dump数据 ),但我只是不明白。
I'm trying to retrieve the following value: 我正在尝试检索以下值:
COM_USERS_REGISTRATION_SAVE_FAILED
And store it as a variable. 并将其存储为变量。 Here is the absolute mess (that I don't understand) that I'm trying to retrieve it from (it's the very last line of text):
这是我要从中检索的绝对混乱(我不理解)(这是文本的最后一行):
object(UsersModelRegistration)#98 (9)
{ ["data:protected"]=> object(stdClass)#106 (1) {
["groups"]=> array(1) {
[0]=> string(1) "2" } }
["_forms:protected"]=> array(0) { }
["__state_set:protected"]=> NULL
["_db:protected"]=> object(JDatabaseMySQL)#15 (19) {
["name"]=> string(5) "mysql"
["nameQuote:protected"]=> string(1) "`"
["nullDate:protected"]=> string(19) "0000-00-00 00:00:00"
["dbMinimum:protected"]=> string(5) "5.0.4"
["_database:private"]=> string(15) "table_joomla"
["connection:protected"]=> resource(29) of type (mysql link)
["count:protected"]=> int(0)
["cursor:protected"]=> resource(83) of type (Unknown)
["debug:protected"]=> bool(false)
["limit:protected"]=> int(0)
["log:protected"]=> array(0) { }
["offset:protected"]=> int(0)
["sql:protected"]=> object(JDatabaseQueryMySQL)#126 (18) {
["db:protected"]=> *RECURSION*
["type:protected"]=> string(6) "select"
["element:protected"]=> NULL
["select:protected"]=> object(JDatabaseQueryElement)#127 (3) {
["name:protected"]=> string(6) "SELECT"
["elements:protected"]=> array(1) {[0]=> string(4) "`id`" }
["glue:protected"]=> string(1) "," }
["delete:protected"]=> NULL
["update:protected"]=> NULL
["insert:protected"]=> NULL
["from:protected"]=> object(JDatabaseQueryElement)#128 (3) {
["name:protected"]=> string(4) "FROM"
["elements:protected"]=> array(1) {
[0]=> string(10) "`#__users`" }
["glue:protected"]=> string(1) "," }
["join:protected"]=> NULL
["set:protected"]=> NULL
["where:protected"]=> object(JDatabaseQueryElement)#129 (3) {
["name:protected"]=> string(5) "WHERE"
["elements:protected"]=> array(2) {
[0]=> string(31) "`username` = 'test123@mail.com'"
[1]=> string(9) "`id` != 0" }
["glue:protected"]=> string(5) " AND " }
["group:protected"]=> NULL ["having:protected"]=> NULL
["columns:protected"]=> NULL ["values:protected"]=> NULL
["order:protected"]=> NULL ["union:protected"]=> NULL
["autoIncrementField:protected"]=> NULL }
["tablePrefix:protected"]=> string(6) "s7kou_"
["utf:protected"]=> bool(true)
["errorNum:protected"]=> int(0)
["errorMsg:protected"]=> string(0) ""
["hasQuoted:protected"]=> bool(false)
["quoted:protected"]=> array(0) { } }
["name:protected"]=> string(12) "registration"
["option:protected"]=> string(9) "com_users"
["state:protected"]=> object(JObject)#99 (1) {
["_errors:protected"]=> array(0) { } }
["event_clean_cache:protected"]=> string(19) "onContentCleanCache"
["_errors:protected"]=> array(1) {
[0]=> string(34) "COM_USERS_REGISTRATION_SAVE_FAILED" } }
All the properties of the object are protected, to access them you should implement "getters" to the UsersModelRegistration class / or extend UsersModelRegistration and implement getters 该对象的所有属性都受到保护,要访问它们,您应该对UsersModelRegistration类实现“获取器” /或扩展UsersModelRegistration并实现获取器
/**
* @returns array
*/
public function getErrors(){
return $this->_errors;
}
Have a look at the class source, most likely there is a method that returns this value. 看一下类源,很可能有一个返回该值的方法。 There are solutions to access protected properties ( Reflections or converting the object to an array) but I will not recommend these, as they totally break the OOP principle of encapsulation.
有一些访问受保护属性的解决方案( 反射或将对象转换为数组), 但我不推荐使用这些解决方案,因为它们完全破坏了封装的OOP原理。 The attribute is protected for a reason, you should access it via the public interface of
UserModelRegistration
. 该属性受保护是有原因的,您应该通过
UserModelRegistration
的公共接口来访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.