Re: Constants in strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 06 Jul 2011 12:56:21 +0100, Stuart Dallas wrote:
> My guess is that the preceding $ causes PHP to interpret the next token
> "{XYZ}" as a variable or a constant, but without that preceding $ it has
> no way to know you're trying to use a constant. As Curtis points out,
> the only way to insert a constant into a string is through
> concatenation.
> 
> -Stuart

OK. I should have made myself clearer - I was making an observation with 
regards to constant parsing in strings rather than looking for advice. My 
bad.

My third example showed that "{${XYZ}}" would echo the value of the 
variable called the value of XYZ:
<?php
define ('XYZ','ABC');

$ABC="huh!";

echo "{${XYZ}}\n";
?>
Output - huh!

We could easily re-write the 'echo' line above to be:
echo "{${constant('XYZ'}}\n";

But my example shows that PHP *is* accessing the value of a constant 
without any jiggery-pokery or hacks (e.g. http://www.php.net/manual/en/
language.types.string.php#91628) as it is retrieving the value of ABC 
from the XYZ constant and then looking for a variable of that name.

I admit that I'm no C coder but it may be possible (note, the word "may") 
that a change of code within the PHP source tree will allow us to use 
something like echo "{{XYZ}}" to access the constant value.

Cheers

Dave


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux