>> 3. The weak point of this proposal is the by reference handling for sort et al. Counterpoint: if you pass a variable to preg_match, then matches gets converted from anything to array, so i believe by reference casting should change the original value (https://3v4l.org/XUJ5m <https://3v4l.org/XUJ5m>). This is weird, but consistent.
> The proposal states that âarray functions that operate on an array by reference such as sort or shuffle will not work on an object implementing __toArray() under this proposalâ, and IMO that is consistent with other magical casting behaviors and I wouldnât expect a class implementing __toArray() to be able to be written or referenced like a traditional array.
> Passing an object with toString by reference will change the original variable: https://3v4l.org/77lov <https://3v4l.org/77lov>
Ah, I think I see what you mean. PHPâs making a copy of the string variable once itâs cast, so itâs no longer referencing the original object that implemented the __toString() method. I imagined the __toArray() would function the same. Once the cast is called on the object, itâs a new array variable and can be acted upon as such. What I was trying to get at was that the magic method does not give the ability to write to the original object. If thatâs not clear then I need to update the RFC.