-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
I have an array object with a nested value "foo" that is sometimes an array sometimes a string.
I need to access "foo" and get the underlying object not another ArrayObject
When "foo" = [] I get an array object that I can call toArray to get the underlying value
When "foo" = "bar" my code tries to call toArray and fails
/**
* @return Generator
*/
function getArrayObject() {
// foo is string
yield ArrayObject::fromArray([
'foo' => 'bar',
]);
// foo is array
yield ArrayObject::fromArray([
'foo' => [
'bar',
],
]);
}
foreach (getArrayObject() as $arrayObject) {
$arrayObject->get('foo')->toArray();
}
Fatal error: Uncaught Error: Call to a member function toArray() on stringSuggestions:
- make "unbox" static so I can use something like this
ArrayObject::unbox($arrayObject->get('foo'));- Add a get function that doesn't box
$arrayObject->getRaw('foo');- Add a third flags param to get
// bitwise is cool
$arrayObject->get('foo', null, ArrayObject::NO_BOX);
// or just bool but no more flags possible
$arrayObject->get('foo', null, false);Metadata
Metadata
Assignees
Labels
No labels