简体   繁体   English

使用PHP中的数组语法访问对象属性

[英]Access object property using array syntax in PHP

Does somebody know why accessing an object's property using array syntax works in some php versions but not others? 有人知道为什么使用数组语法访问对象的属性在某些PHP版本中有效但在其他PHP版本中无效吗?

In the following line of code from the Amazon PHP SDK they do this and seems not to work in my dev server but works fine in my local server and production server 在来自Amazon PHP SDK的以下代码行中,他们执行了此操作,并且似乎无法在我的开发服务器中工作,但在本地服务器和生产服务器中工作正常

https://github.com/aws/aws-sdk-php/blob/master/src/Aws/Common/Client/UploadBodyListener.php#L75 https://github.com/aws/aws-sdk-php/blob/master/src/Aws/Common/Client/UploadBodyListener.php#L75

PHP PHP 5.3.10-1ubuntu3.13 with Suhosin-Patch (cli) PHP具有Suhosin-Patch的PHP 5.3.10-1ubuntu3.13(CLI)

Error: 错误:

Fatal error: Cannot use object of type Guzzle\\Common\\Event as array in /mnt/var/www/dev3.pearup.com/common/vendor/aws/aws-sdk-php/src/Aws/Common/Client/UploadBodyListener.php on line 75 致命错误:无法在/mnt/var/www/dev3.pearup.com/common/vendor/aws/aws-sdk-php/src/Aws/Common/Client/UploadBodyListener中将Guzzle \\ Common \\ Event类型的对象用作数组.php行75

You can do this by implementing an ArrayObject . 您可以通过实现ArrayObject来实现。

So the object you send to that function should also be an ArrayObject. 因此,您发送给该函数的对象也应该是ArrayObject。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM