php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52897 Strings variable parsing - complex syntax
Submitted: 2010-09-21 04:56 UTC Modified: 2010-09-27 23:57 UTC
From: chealer at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: chealer at gmail dot com
New email:
PHP Version: OS:

 

 [2010-09-21 04:56 UTC] chealer at gmail dot com
Description:
------------
Strings variables parsing, as documented on http://ca2.php.net/manual/en/language.types.string.php#language.types.string.parsing
is partly broken, or incorrectly documented.
The documentation says:

In fact, any value in the namespace can be included in a string with this syntax. Simply write the expression the same way as it would appear outside the string, and then wrap it in { and }.

But this seems to only work with pre-computed values accessible through variables (using the dollar sign). This works neither for return values of functions in the namespace, nor for constants.

BTW, in the examples, there is an extra backslash for the method example:
This is the value of the var named by the return value of \$object->getName():

Test script:
---------------
<?php
namespace test;

$working = "works";
const MAYBENOT = "doesnt";
function surelynot() {
	return "neither";
}

$str = <<< DOC
A {$working} B {MAYBENOT} C {surelynot()} D
DOC;
echo $str;


Expected result:
----------------
A works B doesnt C neither D

Actual result:
--------------
A works B {MAYBENOT} C {surelynot()} D

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-21 05:24 UTC] joey@php.net
patch #303636 documents the fact that surelynot() does not work
 [2010-09-22 10:28 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2010-09-22 10:28 UTC] aharvey@php.net
Cheers Joey.

The use of the word "namespace" actually predates PHP itself gaining namespaces -- it's presumably meant to mean "any variable you can access in the current scope". I'll rewrite that paragraph to remove the ambiguity.
 [2010-09-22 10:31 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=303666
Log: Fix doc bug #52897 (Strings variable parsing - complex syntax).
 [2010-09-22 10:31 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-09-22 10:31 UTC] aharvey@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2010-09-22 10:32 UTC] aharvey@php.net
-Type: Bug +Type: Documentation Problem -Package: Unknown/Other Function +Package: Documentation problem
 [2010-09-27 23:57 UTC] chealer at gmail dot com
Thank you aharvey. Well done finding that namespace was used before they existed! The new version restricts what can be expressed, but is now over-restrictive. For instance, elements of array variables can be accessed with complex syntax ({$arr['bar]}).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 05 02:00:01 2025 UTC