Constants in double-quoted strings
| From: | Josh | Date: | Wed, 29 Oct 2008 04:17:42 +0000 |
| Subject: | Constants in double-quoted strings | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-41541@lists.php.net to get a copy of this message | ||
Hello,
What is the chance of support for constants in double-quoted strings
in PHP 5.3 or PHP 6.0?
This is something I have wanted for some time now.
Use cases:
Writing an SQL query that makes use of a status field
<?php
define ('STATUS_ACTIVE', 1);
define ('NUM_PER_PAGE', 25);
$q = "SELECT ID, Name FROM Projects WHERE StatusID = " . STATUS_ACTIVE
. " LIMIT " . NUM_PER_PAGE . " OFFSET {$offset}";
$res = mysql_query ($q);
?>
Syntax suggestions:
Constants would need to be contained within curly braces. e.g.
"SELECT ID, Name FROM Projects WHERE StatusID = {STATUS_ACTIVE} LIMIT
{NUM_PER_PAGE} OFFSET {$offset}"
The syntax would therefore be:
'{', one or more of [-_a-zA-Z0-9], '}'
If not constant is found, the string should be inserted directly.
If that causes too much parsing issues, perhaps a symbol should be
placed before or after the opening brace. e.g.
"SELECT ID, Name FROM Projects WHERE StatusID = {#STATUS_ACTIVE} LIMIT
#{NUM_PER_PAGE} OFFSET {$offset}"
Regards,
Josh