2013-02-10 2 views
2

잠시 동안 get_object_vars을 사용했습니다. 항상 객체의 공개 속성 만 반환하지만 갑자기 보호 된 vars를 반환합니다. 어떻게 그렇게 될수 있니? 그것은 코드 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 
) 

답변

4

가 아니,이없는 새로운 행동이나 밤새 컴퓨터에 들보 된 행동이라고 한 적이있다. the documentation에서

:

는 범위가 지정된 객체에 대한 객체 정의 된 접근이 아닌 정적 속성의 연관 배열을 돌려줍니다.

액세스 수준에 대한 언급이 없습니다.

이가 있다는 사실에 유의하십시오

그러나 동일한 문서 페이지에 다음과 같은 코멘트를 남겼 사용자에 의해보고 된 가시성 및 범위에 내려 오는 문서화되지 않은면은이 입니다 범위에 민감합니다. 개체 소유 메서드에서 this를 호출하면 private 및 protected 변수도 출력됩니다. 객체 외부에서 호출하면 결과를 보관하려는 대상이됩니다.

문서는 친구입니다. 을 사용하십시오.

+0

괜찮 았지만 범위에 민감하지 않은 방식으로 모든 공개 속성을 검색하는 방법은 무엇입니까? – clarkk

+1

@clarkk : 내 _whole_ 답변을 읽으십시오. 처음 몇 라인 만이 아닙니다. –

+0

'클로저'를 사용하여 범위 컨텍스트를 깨뜨릴 수 있습니다. 뭔가 :'$ getPublic = function ($ var) {return get_object_vars ($ var); } $ publicProps = $ getPublic ($ row);' –

0

어떤 PHP 버전을 사용하고 있습니까?

Data_model_Accounting :: get_object_vars를 호출하는 경우 보호 된 속성이 표시되어야합니다.

관련 문제