You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 */functiongetArrayObject() {
// foo is stringyield ArrayObject::fromArray([
'foo' => 'bar',
]);
// foo is arrayyield ArrayObject::fromArray([
'foo' => [
'bar',
],
]);
}
foreach (getArrayObject() as$arrayObject) {
$arrayObject->get('foo')->toArray();
}
Fatal error: Uncaught Error: Call to a member function toArray() on string
Suggestions:
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);
Activity