|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50228 Add function to eval strings as if they were heredoc'd
Submitted: 2009-11-19 11:50 UTC Modified: 2019-09-02 14:28 UTC
From: RQuadling at GMail dot com Assigned:
Status: Suspended Package: Strings related
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:


 [2009-11-19 11:50 UTC] RQuadling at GMail dot com

I would like to suggest a heredoc() function along the lines of ...

string heredoc(string $template, [boolean $suppressErrors [, array 

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.

$name = 'Richard';

$template = 'My name is {$name}';

$result = <<< END_RESULT
My name is {$name}.

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.


Richard Quadling.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-29 12:19 UTC]
-Summary: A function to eval strings as if they were heredoc'd. +Summary: Add function to eval strings as if they were heredoc'd -Package: Feature/Change Request +Package: *General Issues -Operating System: Irrelevant +Operating System: * -PHP Version: 5.3SVN-2009-11-19 (snap) +PHP Version: *
 [2019-09-02 14:28 UTC]
-Status: Open +Status: Suspended -Package: *General Issues +Package: Strings related
 [2019-09-02 14:28 UTC]
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 22 22:01:41 2021 UTC