|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-05-02 12:33 UTC] 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? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 22 22:00:01 2025 UTC |
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