Req #50228 [Opn->Sus]: Add function to eval strings as if they were heredoc'd
Edit report at https://bugs.php.net/bug.php?id=50228&edit=1
ID: 50228
Updated by: cmb@php.net
Reported by: RQuadling at GMail dot com
Summary: Add function to eval strings as if they were
heredoc'd
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: *General Issues
+Package: Strings related
Operating System: *
PHP Version: *
Block user comment: N
Private report: N
New Comment:
This feature certainly requires discussion on internals and likely
the RFC process[1]. Feel free to start it. For the time being,
I'm suspending this ticket.
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2009-11-19 11:50:54] RQuadling at GMail dot com
Description:
------------
Hello.
I would like to suggest a heredoc() function along the lines of ...
string heredoc(string $template, [boolean $suppressErrors [, array
&missingVariables]])
The purpose of the the function would be to allow the contents of a
string to be interpreted just as if it had been supplied as a variable
rather than as a constant.
So the output of the example below would be Match.
<?php
$name = 'Richard';
$template = 'My name is {$name}';
$result = <<< END_RESULT
My name is {$name}.
END_RESULT;
echo $result === heredoc($template) ? 'Match' : 'Different';
?>
Currently, to expand a template, output buffering and/or string/regex
search/replace is required. Also eval() COULD be used but that has its
own issues.
But it would seem all the processing logic already exists in the
heredoc functionality.
Providing a function based upon the same functionality would certainly
make templating easier.
The ability to suppress the generation of the errors and to capture
the names of missing variables would allow for a degree of flexibility
beyond the current implementation of heredoc, but could be worthwhile.
Regards,
Richard Quadling.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=50228&edit=1
Thread (2 messages)