Collection class shouldn't cast to string?! #44341
Unanswered
buddhaCode
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks,
I just stumbled across a strange behavior where my collection object was implicitly casted to a string. This was odd and I was expecting a PHP type error instead. Or at least not a string cast.
So my question: Why does the collection class implement the __toString method. This doesn't make any sense to me.
Here my code:
In this example
$foo->bar
ends up being a string["foo", "bar"]
. First I was expecting a type error. On a second thought, the collection is implementing the ArrayAccess interface. So I would expect an implicit cast to array.What do you think?
Best,
Arne
Beta Was this translation helpful? Give feedback.
All reactions