Re: [PHP-DEV] Proposal for a RFC

This is only part of a thread. view whole thread
May 7, 2019 12:57 (Steven Wade)
> On May 7, 2019, at 8:52 AM, Stephen Reay <> wrote: > > >> On 7 May 2019, at 19:47, Steven Wade <> wrote: >> >>> Maybe I’m missing the point (I’ve never used it) of VarDumper, but isn’t this type of thing exactly why the `__debugInfo` magic method exists? >> >> >> I can't speak for the exact reason a library like VarDumper is using casting versus __debugInfo, but in trying to find a substitute this morning, I played with the method you mentioned and found that it can be overwritten by classes and be commanded to not return anything (similar to my __toArray proposal), whereas current functionality prevents overriding casting to an array so casting will always give you insight but users can overwrite __debugInfo and cause unintended effects. I assume that's the reason for not using __debugInfo. >> >> -- >> Steven Wade >> >> >> >> > > Right, I understand that it *can* be overridden, but surely if someone’s doing that, its because they want more useful information provided in, e.g. var_dump.
I think that's a good point. If we follow that mentality, then the proposed __toArray and it's subsequent ability to affect array casting isn't a worry too much as the proposal is to only call __toArray if it exists and an object is cast to an array, so if a user manually implements __toArray, then we could assume "they want more useful information provided in, e.g. var_dump." -- Steven Wade