Req #76295 [Opn->Wfx]: Add a __toHeredoc magic method
Edit report at https://bugs.php.net/bug.php?id=76295&edit=1
ID: 76295
Updated by: requinix@php.net
Reported by: email at davekok dot nl
Summary: Add a __toHeredoc magic method
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
There is more to this than just adding another magic method. It has some serious implications about
what heredocs can be and how they should work. And I can think of some complexities regarding when
it should be used or not that would need to be addressed.
But really, this is something that can be done easily with a regular userland method.
echo <<<FOO
<p>This is a {$object->render("html")} object.</p>
FOO;
echo <<<BAR
This is a {$object->render("text")} object.
BAR;
If you feel strongly about PHP needing dedicated support for this then check out the RFC process.
https://wiki.php.net/rfc/howto
Previous Comments:
------------------------------------------------------------------------
[2018-05-02 12:33:31] email at davekok dot nl
Description:
------------
Feature request.
At moment PHP has the very useful __toString() magic method. However at times I find myself needing
to convert an object to different string representations based on the output language used, like
HTML, CSS, Json, CSV. When using heredoc it would be useful if the identifier could be used to
distinguish between different types of languages similar to how markdown works.
Would it be possible to add a __toHeredoc(string $identifier) magic method that a programmer could
implement? With a fallback to using __toString() magic method if it is missing?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76295&edit=1
Thread (2 messages)