A mostly unknown perhaps useless but sorta neat PHP coding trick

Yesterday while documenting that PHP 6 deprecates $string{42} in favor of $string[42] I stumbled upon a comment within the PHP Manual XML sources, and here it is in its entirety:

<!-- maybe it's better to leave this out?? 
// this works, but i disencourage its use, since this is NOT 
// involving functions, rather than mere variables, arrays and objects.
$beer = 'Heineken';
echo "I'd like to have another {${ strrev('reeb') }}, hips";
 -->

The thought of a function being called from within a string (without eval()) seems a little odd, doesn’t it? Well, the above code in fact works. Not sure how useful it is but likely someone will find a creative use or two. The internals team generally feels that the behavior isn’t worth documenting as it’s simply an ugly and poor coding style BUT, maybe you’ll see it (the “{${ func() }}” syntax) on a PHP exam somewhere so now you know… :-)

History: This information was added within a patch titled “Added jeroen’s updates” by Damien Seguy apparently for Jeroen van Wolffelaar on the date Thu May 10 18:01:04 2001 UTC.

Update (April 20, 2007): A few days ago Jani demonstrated a simpler example for these variable functions:

$exec = ‘shell_exec’;

$cmd = ‘ls -l’;

echo “This is embedded exec: {$exec($cmd)}”;

happy 30 something birthday to me

Yesterday was a special day as it represented the time I was born. For the most part it was a typical day except during the evening people were over so we created and ate pizza, drank beer and wine, and hung out. Thanks to everyone who came over (and called) including Curt and James for the food, and Jill for the candled birthday cup cakes. I also appreciate Heather and Jill for letting me sit in between them for much of the evening because girls smell nice.