php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37263 Escaping curly braces produces backslash in output.
Submitted: 2006-05-01 15:36 UTC Modified: 2006-05-01 21:20 UTC
From: dbeckham at dealnews dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.2 OS: Linux (2.6.14)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dbeckham at dealnews dot com
New email:
PHP Version: OS:

 

 [2006-05-01 15:36 UTC] dbeckham at dealnews dot com
Description:
------------
When escaping curly braces in a string, the backslash characters are included in any output.

Reproduce code:
---------------
<?
$test = "test";
echo "\{$test\}\n";
?>


Expected result:
----------------
The above output should be:

{test}


Actual result:
--------------
The actual output is:

\{test\}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-01 19:32 UTC] judas dot iscariote at gmail dot com
this is not a bug, it's a behaviour change of the engine.
see.

http://bugs.php.net/bug.php?id=35527

and the documentation here:

"Before PHP 5.1.1, backslash in \{$var} hasn't been printed."

"(Use "{\$" to get a literal "{$")." [1]

[1] http://php.net/manual/en/language.types.string.php
 [2006-05-01 20:01 UTC] dbeckham at dealnews dot com
I disagree, this *is* a bug.  You can't have it both ways, either the curly brace is not a special character and does not need to be escaped, or it is a special character used for complex variables and can be escaped.  What you have right now is neither ... it's a special character and removed from the output when used with a complex variable, but if escaped, it's not used with the complex variable and additionally the backslash is added to the output.

By the way, my intention was never to produce {$ in the output, but only to make sure the curly brace was output along with the variable.
 [2006-05-01 20:09 UTC] dbeckham at dealnews dot com
Here is another example to highlight the problem:

php -r '$test = array(array(0,1), array(2,3)); echo "{$test[1][0]}\n";'

This should produce the following output:
2


php -r '$test = array(array(0,1), array(2,3)); echo "\{$test[1][0]}\n";'

This produces:
\{Array[0]}


Since curly braces are no longer special characters, should not echo "\{$test[1][0]}\n"; produce the following?
\2
 [2006-05-01 20:56 UTC] judas dot iscariote at gmail dot com
php -r '$test = array(array(0,1), array(2,3)); echo
"\{$test[1][0]}\n";'

outputs in PHP 4.3.11 and PHP 4_4 dev

{Array[0]}

in PHP 5_1 CVS outputs

\{Array[0]}

is consistent with the mentioned change, it just output the slash now.

but seems that it may output "\2" as you said,however, that will be another behaviour change, and Im sure we don't want that right ?

this seems to be a documentation problem
 [2006-05-01 21:06 UTC] dbeckham at dealnews dot com
You are still missing my point.  How can curly braces no longer be a special character, yet escaping them *changes* the behavior of PHP?

If {$test} produces only the value of $test without curly braces, how on earth can \{$test} not produce the value of $test with a backslash in front of it?

Is a curly brace special or not?

If you are not a PHP developer and do not have the ability to change the status of this ticket and officially say that this bug will or will not be corrected, please move on.  I'm not interested in a 3rd party debate about this issue.
 [2006-05-01 21:20 UTC] mike@php.net
This is not a bug. Escaping behaviourhas been changed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 15:01:28 2024 UTC