使用PHP访问对象中的数组

时间:2017-08-29 14:20:05

标签: php arrays object

如何使用PHP访问以下对象中的TXN_ID?下面是对象的print_r:

Option Explicit

Private Sub CommandButton1_Click()

    Dim Prod As Variant
    Dim Dev As Variant
    Dim counter As Integer
    Dim i As Integer

    Prod = Array("ZS7_656", "PCO_656")
    Dev = Array("NSA_103", "DCA_656")
    counter = UBound(Prod)
    i = 0

    For i = 0 To counter

        Set x = Workbooks.Open("C:\Users\*****\Desktop\New folder\" & Prod(counter) & ".xls")
        Set Z = Workbooks.Open("C:\Users\*****\Desktop\New folder\" & Dev(counter) & "_A.xls")

        With x.Sheets(Prod(counter))
            Set aCell1 = .Range("A1:X1000") _
                .Find(What:="User", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
            .Range(aCell1, .Cells(.Rows.Count, aCell1.Column).End(xlUp)) _
                .Offset(2, 0) _
                .Copy ThisWorkbook.Sheets(Prod(counter)).Range("A2")
        End With

        LastRow = ThisWorkbook.Sheets(Prod(counter)).Columns("A").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
        LastRow2 = Z.Sheets(Dev(counter) & "_A").Columns("B").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
        Set Table1 = ThisWorkbook.Sheets(Prod(counter)).Range("A2:A" & LastRow)
        Set Table3 = Z.Sheets(Dev(counter) & "_A").Range("B1:B" & LastRow2)
        A1 = ThisWorkbook.Sheets(Prod(counter)).Range("K2").Row
        A2 = ThisWorkbook.Sheets(Prod(counter)).Range("K2").Column
        For Each Item In Table1
            On Error Resume Next
            ThisWorkbook.Sheets(Prod(counter)).Cells(A1, A2) = Application.WorksheetFunction.VLookup(Item, Table3, 1, False)
            On Error GoTo 0
            A1 = A1 + 1
        Next Item

        x.Close
        Z.Close
    Next counter

End Sub

我在错误日志中得到了这个:

$txn_object = $txn_params[last_payment];
error_log( print_r($txn_object,true) );

我已经尝试了一些东西,但似乎无法获得该值,但又回来了:

EE_Payment Object
(
    [_props_n_values_provided_in_constructor:protected] => Array(
        [PAY_ID] => 4168
        [TXN_ID] => 746919
        [STS_ID] => PAP
        [PAY_timestamp] => 2017-08-29 14:06:26
        [PAY_source] => CART
        [PAY_amount] => 24.000
        [PMD_ID] => 11
        [PAY_gateway_response] => submitted_for_settlement
        [PAY_txn_id_chq_nmbr] => 96g71gxv
        [PAY_po_number] => 
        [PAY_extra_accntng] => 
        [PAY_details] => 
    )
)

2 个答案:

答案 0 :(得分:3)

您无法从Object(类)外部访问TXN_ID元素,因为_props_n_values_provided_in_constructor属性为protected

  
      
  • 公共范围,使该变量/函数可以从对象的任何地方,其他类和实例中获得。
  •   
  • 私有范围,当您希望变量/函数仅在其自己的类中可见时。
  •   
  • 当你想让你的变量/函数在扩展当前类的所有类中都可见时保护范围,包括   父母班。
  •   

https://stackoverflow.com/a/4361582/5465663

进入PHP documentation

答案 1 :(得分:2)

停止使用print_r对对象进行反向工程并阅读文档/来源。

你有一个EE_Payment对象,它是Event Espresso库的一部分。 The source of this class is available here,并显示一个名为TXN_ID的方法,以返回交易ID。

$id = $txn_object->TXN_ID();

可以满足您的需求。