Re: [PHP] Broken compatibility with escaping { in php 5.2



On cs, 2007-01-18 at 14:19 +0100, Jochem Maas wrote:
Bogdan Ribic wrote:
Hi all,

Try this:

$a = '';
echo "\{$a}";

from php 4, it outputs "{}", from php 5.2 (one that comes with Zend 5.5)

no-one here supports Zend.

it outputs "\{}", thus breaking existing scripts.

AFAICT the escaping in that string is wrong - the fact that it did work
the way you want it to is probably sheer luck.

lastly I ran your tests and determined at the least that the 'break'
occur *prior* to 5.2. at a guess it probably changed in 5.0, here are my results:

# php -r 'echo "php",phpversion(),":\n"; $a = ""; var_dump("\{$s}");' ;
php5 -r 'echo "php",phpversion(),":\n"; $a = ""; var_dump("\{$s}");'

OUTPUT:

php4.3.10-18:
string(2) "{}"
php5.1.2:
string(3) "\{}"



be pragmatic - fix your script :-)

is this the correct form:

$a = '';
echo "\{$a\}";

if I want to get "{}" a result?

(I think it is)

greets
Zoltán Németh


.



Relevant Pages

  • Re: [PHP] Broken compatibility with escaping { in php 5.2
    ... no-one here supports Zend. ... AFAICT the escaping in that string is wrong - the fact that it did work ...
    (php.general)
  • Re: set user=%username%
    ... Your most recent feedback confirms that Windows is ... Type this: echo %MyName% ... > usertest=This is a long string. ...
    (microsoft.public.windows.server.general)
  • Re: its not the school home work
    ... I've learned a bit about strong quotes and think I realized when to ... the shell (such as in the $var, but also for the spaces (that ... echo "foo bar" ... you may say that $string does not appear in /list/ context so ...
    (comp.unix.shell)
  • Re: TRUE and FALSE are treated differently
    ... No -- you can't echo a boolean in PHP. ... If you look up the manual on type casting, you'll find that FALSE is cast ... to an empty string, and TRUE is cast to a non-empty string. ...
    (comp.lang.php)
  • Re: TRUE and FALSE are treated differently
    ... No -- you can't echo a boolean in PHP. ... the boolean is implicitly cast to a string. ... If you look up the manual on type casting, you'll find that FALSE is cast to an empty string, and TRUE is cast to a non-empty string. ...
    (comp.lang.php)