[英]PHP echo value of a object from array
I have a array which I am printing using print_r. 我有一个要使用print_r打印的数组。
<?php
print_r ($this)
?>
I get following result in my browser. 我在浏览器中得到以下结果。
PackingListForm Object
(
[objShipment:protected] => Shipment Object
(
[objCustomFieldArray] =>
[intShipmentId:protected] => 38
[strShipmentNumber:protected] => 1035
[intTransactionId:protected] => 97
[intFromCompanyId:protected] => 1
[intFromContactId:protected] => 1
[intFromAddressId:protected] => 1
[intToCompanyId:protected] => 2
[intToContactId:protected] => 3
[intToAddressId:protected] => 2
[intCourierId:protected] => 1
[strTrackingNumber:protected] =>
[dttShipDate:protected] => QDateTime Object
)
)
Now I want to print / echo intTransactionId. 现在我要打印/回显intTransactionId。
I have used following variable to echo the result, but I am getting undefined variable. 我已经使用了以下变量来回显结果,但是却得到了未定义的变量。
<?php
$noted = $this->objShipment->intTransactionId;
print_r ($noted);
?>
I am getting following php exception error in my browser. 我在浏览器中收到以下php异常错误。
Undefined GET property or variable in 'Shipment' class: intTransactionId Line 33: $noted = $this->objShipment->intTransactionId; 'Shipment'类中未定义的GET属性或变量:intTransactionId第33行:$ noted = $ this-> objShipment-> intTransactionId;
My question is how can I echo / print value of intTransactionId? 我的问题是如何回显intTransactionId的值?
First try to convert it into array and then it will be much easier :), 首先尝试将其转换为数组,然后会容易得多:),
$newArray = (array)$this;
print_r($newArray);//to see what can you get from there
// get_object_vars
$newArray = get_object_vars($object);
The object is from class PackingListForm, have look on that class if you have access and see if there is any get() function. 该对象来自PackingListForm类,如果可以访问,请查看该类,然后查看是否有任何get()函数。
intTransactionId
is a protected property which means that you can't access it outside of the class itself (or parennt class or child class). intTransactionId
是一个受保护的属性,这意味着您不能在类本身(或父类或子类)之外访问它。
The exception, I think, is thrown in a __get
magic method defined in Shipment
(or one of its parent classes). 我认为,例外是在Shipment
(或其父类之一)中定义的__get
magic方法中引发的。 This method is called when trying to access an unset property (or non-accesible property). 尝试访问未设置的属性(或不可访问的属性)时,将调用此方法。
Please check this behaviour. 请检查此行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.