# __repr() magic method (was Re: Proposal: short_var_export($value, bool $return=false, int $flags=0))

- Thread: https://externals.io/message/112940
- Original archive: https://news-web.php.net/php.internals/112940
- Started by Ben Ramsey on 2021-01-20T16:27:39+00:00
- Messages: 3
- RFC: Stringable (Implemented (PHP 8.0)) — https://externals.io/rfc/stringable.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #112940 — Ben Ramsey — 2021-01-20T16:27:39+00:00

URL: https://externals.io/message/112940#112940

> 
> 
> 
> > […]
> 
> I am considering to try and introduce a __repr() magic method that is
> similar to the __repr__() method from Python. Having a var_repr() method
> which does not use the __repr() method would be confusing. So I would
> like to suggest not to use that name.
> 
> As the intent of the resulting string is to obtain PHP code that will
> construct the variable, another option might be: var_constructor().
> 
> Regards,
> Dik Takken


Taking this to a new thread so I don’t derail the `short_var_export()` thread.

Dik, I like this addition, but I think the name “repr” might be confusing to PHP developers who aren’t familiar with Python idioms. PHP function names and coding standards within the community tend to lean more toward verbosity than terseness, when it comes to naming things.

Perhaps we should follow the lead of `__toString()` and use `__toRepresentation()`? Maybe also introduce a `Representable` interface, like `Stringable`? https://wiki.php.net/rfc/stringable

Cheers,
Ben

---

## #112941 — Marco Pivetta — 2021-01-20T16:28:49+00:00

URL: https://externals.io/message/112940#112941 · In reply to: #112940

> Taking this to a new thread so I don’t derail the `short_var_export()`
> thread.
>
> Dik, I like this addition, but I think the name “repr” might be confusing
> to PHP developers who aren’t familiar with Python idioms. PHP function
> names and coding standards within the community tend to lean more toward
> verbosity than terseness, when it comes to naming things.
>
> Perhaps we should follow the lead of `__toString()` and use
> `__toRepresentation()`? Maybe also introduce a `Representable` interface,
> like `Stringable`? https://wiki.php.net/rfc/stringable
>

Ooof, can we just avoid more magic methods overall? :|

Marco Pivetta

http://twitter.com/Ocramius

http://ocramius.github.com/

---

## #112942 — Ben Ramsey — 2021-01-20T16:30:50+00:00

URL: https://externals.io/message/112940#112942 · In reply to: #112941

> 
> 
> 
> > […]
> 
> Ooof, can we just avoid more magic methods overall? :|


I think that ship has sailed, friend. ;-)

Cheers,
Ben
