note 91628 added to language.types.string

From: Date: Sat, 20 Jun 2009 07:43:20 +0000
Subject: note 91628 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-157168@lists.php.net to get a copy of this message
Here is an easy hack to allow double-quoted strings and heredocs to contain arbitrary expressions in curly braces syntax, including constants and other function calls: <?php // Hack declaration function _expr($v) { return $v; } $_expr = '_expr'; // Our playground define('qwe', 'asd'); define('zxc', 5); $a=3; $b=4; function c($a, $b) { return $a+$b; } // Usage echo "pre {$_expr(1+2)} post\n"; // outputs 'pre 3 post' echo "pre {$_expr(qwe)} post\n"; // outputs 'pre asd post' echo "pre {$_expr(c($a, $b)+zxc*2)} post\n"; // outputs 'pre 17 post' // General syntax is {$_expr(...)} ?> ---- Server IP: 69.147.83.197 Probable Submitter: 217.77.54.234 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/91628 Del: integrated -- https://master.php.net/note/delete/91628/integrated Del: useless -- https://master.php.net/note/delete/91628/useless Del: bad code -- https://master.php.net/note/delete/91628/bad+code Del: spam -- https://master.php.net/note/delete/91628/spam Del: non-english -- https://master.php.net/note/delete/91628/non-english Del: in docs -- https://master.php.net/note/delete/91628/in+docs Del: other reasons-- https://master.php.net/note/delete/91628 Reject -- https://master.php.net/note/reject/91628 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157168) next »