PHP retrieving array values using dash arrow “->”

╄→尐↘猪︶ㄣ 提交于 2019-12-03 22:31:47

As stated before in other answers, using -> means you are accessing an object, not an array.

However, it is sometimes possible that an object would be treated as an array. It is when it is implementing ArrayAccess interface. The coder can do such that eg. calling $object->field would be equivalent to $object['field'], but he/she must not.

Moreover, it is possible to treat an array as an object (refer to the manual), however in this case it is not an array but an object and is the same way as above.

The variables that allow you get properties with -> are actually objects, not arrays. They do allow the ['some_key'] syntax, but that doesn't mean they are arrays. They are not.

You can reading more about objects on this page of the PHP manual.

Those aren't arrays, they're objects.

That is because it is not an array it is an objects variable.

For example;

class MyObject{

   var $myVariable = 'test';

}

$MyObject = new MyObject();
echo $MyObject->myVariable; // Would return 'test'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!