大佬教程收集整理的这篇文章主要介绍了使用PHP访问对象的属性,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用PHP访问对象的一部分.我可以访问某些部分,但是,当我尝试访问包含信用卡号的后4位的部分时,它只会打印出NULl.这是我的代码:
$customer = Braintree_Customer::find('51658462');
echo var_dump($customer);
这将打印出对象.这是部分打印输出:
object(Braintree_Customer)#1 (1) {
["_attributes"]=>
array(14) {
["id"]=>
String(8) "51658462"
["merchantId"]=>
String(16) "tyn83x4j454dnvmt"
["firstName"]=>
String(4) "Demo"
["lastName"]=>
String(7) "Account"
["company"]=>
NULL
["phone"]=>
String(12) "555-555-5555"
["fax"]=>
NULL
["website"]=>
NULL
["createdAt"]=>
object(datetiR_914_11845@E)#8 (3) {
["date"]=>
String(19) "2013-08-14 15:19:26"
["timezone_type"]=>
int(3)
["timezone"]=>
String(3) "UTC"
}
["updatedAt"]=>
object(datetiR_914_11845@E)#9 (3) {
["date"]=>
String(19) "2013-08-14 15:19:27"
["timezone_type"]=>
int(3)
["timezone"]=>
String(3) "UTC"
}
["customFields"]=>
String(3) "
"
["creditCards"]=>
array(1) {
[0]=>
object(Braintree_CreditCard)#2 (1) {
["_attributes"]=>
array(29) {
["bin"]=>
String(6) "371275"
["expirationMonth"]=>
String(2) "01"
["expirationYear"]=>
String(4) "2016"
["last4"]=>
String(4) "1234"
我正在尝试访问last4属性.我尝试了几种不同的方法,但是没有一种起作用.我以为echo var_dump($customer-> creditCards-> last4);会给我价值,但不会.我想念什么?
解决方法:
var_dump($customer->creditCards[0]->last4);
creditCards是@L_674_6@包含一项的数组-仅供参考,您无需回显var_dump的结果.
以上是大佬教程为你收集整理的使用PHP访问对象的属性全部内容,希望文章能够帮你解决使用PHP访问对象的属性所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。