Generic expressions interpolation in strings
| From: | Federico Giannici | Date: | Sun, 05 Jan 2003 18:45:06 +0000 |
| Subject: | Generic expressions interpolation in strings | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-93159@lists.php.net to get a copy of this message | ||
I already opened a bug (#21433) about this Feature Request, but I
realized it is better to discuss here about it.
I'm relatively new to PHP. Previously I used to program a lot in Perl.
What I really lack in PHP is Perl's ability to interpolate any
expression inside a string.
For example:
Perl: "Next value is @{[ $value + 1 ]}!"
PHP: "Next value is " . $value + 1 . "!"
In this simple case it's not a great problem, but it becomes more
awkward when using the heredoc operator. In this cases I'm often forced
to use temporary variables:
$tempvar = $value + 1;
print <<< END
Here it is the next value
$tempvar
Other text...
END;
I propose to extend the Variable Parsing syntax to evaluate ANY
expression instead of variables only.
I propose the following syntax:
print <<< END
Here it is the next value
{$= $value + 1 }
Other text...
END;
Using "{=" would be more readable but it would cause too many backward
compatibility problems...
What do you think of this?
Thanks.
--
___________________________________________________
__
|- giannici@neomedia.it
|ederico Giannici http://www.neomedia.it
___________________________________________________