Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand the current __toString behaviour #59

Open
rtheunissen opened this issue Sep 6, 2016 · 4 comments
Open

Expand the current __toString behaviour #59

rtheunissen opened this issue Sep 6, 2016 · 4 comments

Comments

@rtheunissen
Copy link
Member

rtheunissen commented Sep 6, 2016

Python example:

a = dict()
a['a'] = 3
a['b'] = 2
a['c'] = 1

print a
{'a': 3, 'c': 1, 'b': 2}

I had this implemented very very early when php-ds was still private, where the structures would echo something similar to JSON. Values that could not be converted to strings had default fallbacks like object(stdClass)#1 and resource(type)#1.

I imagine the above equivalent would echo something like:

{'a': 3, 'b': 2, 'c': 1}
@nikic
Copy link
Contributor

nikic commented Sep 6, 2016

Does that mean that __toString() will be a debugging handler? I don't think that matches usual semantics, and we already have var_dump().

@rtheunissen
Copy link
Member Author

It's just a different level of verbosity, but you're right, it's not expected behaviour / usual semantics. 😢

@nikita2206
Copy link

@nikic to be honest usual semantics of php in this regard is quite inconvenient. Would it be that bad to change it for a more convenient approach by the cost of consistency with the language?

@rtheunissen
Copy link
Member Author

rtheunissen commented Sep 7, 2016

__toString is either an appropriate representation (think PSR-7 response body) or a debug handler. There is no default handler so I'm not even sure what the "usual semantics of PHP" actually are in this context.

Instead of some custom string representation (mentioned above), what about having all structures just convert to their JSON representation, such that echo $structure is equivalent to echo json_encode($structure). That's both an appropriate representation and a debug handler at the same time.

FWIW, structures currently convert to this format: "object(Ds\Map)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants