我现在已经使用get_object_vars
了一段时间..它总是只返回一个对象的公共属性,但突然它也会返回受保护的变量?!?怎么可能?
print_r($row);
print_r(get_object_vars($row));
Data_model_Accounting Object
(
[get_external:protected] => 1
[put_external:protected] => 1
[delete_external:protected] => 1
[post_class:protected] => 1
[external_field_const:protected] => Array
(
[type] => Array
(
[0] => LEDGER
[1] => DEBTOR_LEDGER
[2] => CREDITOR_LEDGER
[3] => DEBTOR_INVOICE
[4] => CREDITOR_INVOICE
)
)
[external_field_condition_unset:protected] => Array
(
[invoice_id_] => Array
(
[type] => Array
(
[mode] => not_in
[values] => Array
(
[0] => DEBTOR_INVOICE
[1] => CREDITOR_INVOICE
)
)
)
[invoice_time_due] => Array
(
[type] => Array
(
[mode] => not_in
[values] => Array
(
[0] => DEBTOR_INVOICE
[1] => CREDITOR_INVOICE
)
)
)
)
[table:protected] =>
[predata:protected] => Array
(
)
[data:protected] => Array
(
)
[external:protected] => 1
[put_error:protected] =>
[action_mode:protected] =>
[Shell:protected] =>
[access_admin_primary:protected] => 1
[get_admin_external:protected] =>
[put_admin_external:protected] =>
[delete_admin_external:protected] =>
[id] => 19
[time] => 1362787200
[type] => DEBTOR_LEDGER
[account_id_] => 16000
[account_name] => Debitor
[accountoff_id_] => 16000
[accountoff_name] => Debitor
[vatcode_name] =>
[subaccount_id_] => 10
[subaccount_type] => DEBTOR
[subaccount_name] => hehe
[subaccountoff_id_] => 101
[subaccountoff_type] => DEBTOR
[subaccountoff_name] => oskel
[dimension_name] =>
[dimensionoff_name] =>
[currency_name] =>
[invoice_id_] =>
[invoice_time_due] => 0
[amount] => -165
[currency_amount] => -165
[currency_rate] => 1
)
Array
(
[table] =>
[predata] => Array
(
)
[data] => Array
(
)
[external] => 1
[put_error] =>
[action_mode] =>
[Shell] =>
[access_admin_primary] => 1
[get_admin_external] =>
[put_admin_external] =>
[delete_admin_external] =>
[id] => 19
[time] => 1362787200
[type] => DEBTOR_LEDGER
[account_id_] => 16000
[account_name] => Debitor
[accountoff_id_] => 16000
[accountoff_name] => Debitor
[vatcode_name] =>
[subaccount_id_] => 10
[subaccount_type] => DEBTOR
[subaccount_name] => hehe
[subaccountoff_id_] => 101
[subaccountoff_type] => DEBTOR
[subaccountoff_name] => oskel
[dimension_name] =>
[dimensionoff_name] =>
[currency_name] =>
[invoice_id_] =>
[invoice_time_due] => 0
[amount] => -165
[currency_amount] => -165
[currency_rate] => 1
)
答案 0 :(得分:3)
不,这不是新行为,也不是一夜之间传到你电脑里的行为。
返回范围内指定对象的已定义对象可访问非静态属性的关联数组。
未提及访问级别。
但是, 是一个未记录的方面,归结为可见性和范围,由在同一文档页面上留下以下注释的用户报告:
请注意这是范围敏感的事实。 如果您是从对象自己的方法调用它,那么也将输出私有和受保护的变量。从对象外部调用它,结果很可能是您要存档的内容。
文档是你的朋友。 使用。
答案 1 :(得分:0)
您使用的是哪个版本的PHP?
如果您在Data_model_Accounting :: method中调用get_object_vars,那么受保护的属性应该是可见的。