php how to access object array

后端 未结 3 1661
甜味超标
甜味超标 2020-12-21 09:43

How to access the item array from the following object array

Cart66Cart Object
(
[_items:Cart66Cart:private] => Array
    (
        [2] => Cart66CartI         


        
3条回答
  •  时光取名叫无心
    2020-12-21 10:10

    Something like this maybe:

    $object->_items[index]->_productId
    

    But if _items is private you will need a public getter or mess with the Reflection classes. You can set the the private property to be accessible through ReflectionProperty Try this:

        $reflectionObject = new ReflectionObject($yourObject);
        $property = $reflectionObject->getProperty('_items');
        $property->setAccessible(true);
        $items = $property->getValue($yourObject);
    

提交回复
热议问题