php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52526 Documentation for T_STRING implying bad programming style
Submitted: 2010-08-03 18:17 UTC Modified: 2010-10-19 06:15 UTC
From: + at ni-po dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2010-08-03 18:17 UTC] + at ni-po dot com
Description:
------------
The appendix token documentation for T_STRING implies a bad programming style. As an example it gives `"$a[a]"`. According to the PHP documentation this is incorrect syntax, the correct one is `"$a['a']"` (which would result in a T_CONSTANT_ENCAPSED_STRING, not T_STRING.) `"$a[a]"` works, but only throwing a notice.

Furthermore all the other uses of this allrounder-token are not mentioned (e.g. for function, class and method names, constant names, ..., ...)

Proposed text:
<row>
    <entry><constant>T_STRING</constant></entry>
    <entry>identifier</entry>
    <entry>identifier, e.g. function or class name</entry>
</row>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-04 11:20 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=301848
Log: Fixed bug #52526 (Documentation for T_STRING implying bad programming style)
 [2010-08-04 11:20 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-08-04 11:20 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2010-08-04 12:09 UTC] salathe@php.net
The change does not address the issue. Changing the `"$a[a]"` to `"$a['a']"` only 
serves to break the example (literally, it will generate a parse error).

The point, I think, was that the reporter (mistakenly) did not like the idea of 
using a "bad practice".  However, "$a[a]" is perfectly acceptable (within a 
string!) and will not generate any notices.  

The description could do with mentioning that T_STRING also means 
class/function/etc. names as well.
 [2010-08-04 12:09 UTC] salathe@php.net
-Status: Closed +Status: Re-Opened
 [2010-08-05 12:37 UTC] + at ni-po dot com
salathe is perfectly right (in all points). I didn't realize, that "$a[a]" is valid within a string. (Actually I had my thoughts on the complex variable syntax "{$a[a]}" there it *would* be a notice.) I am sorry for that. But the point about not mentioning identifiers like class and function name is still valid.

<row>
    <entry><constant>T_STRING</constant></entry>
    <entry>"$a[a]", identifier</entry>
    <entry>string array index inside string or identifier, e.g. function or class name</entry>
</row>
 [2010-08-05 13:01 UTC] + at ni-po dot com
Better turn it round or it is ambiguous (array index inside identifier one could think):

<row>
    <entry><constant>T_STRING</constant></entry>
    <entry>identifier, "$a[a]"</entry>
    <entry>identifier ( e.g. function or class name) or string array index inside string</entry>
</row>
 [2010-09-27 09:58 UTC] salathe@php.net
See also #52927 referencing the misinformation from the committed "fix" for this 
bug.
 [2010-09-29 19:57 UTC] stephan dot soller at helionweb dot de
I'm sorry for the duplicate (#52927). I've tested the original syntax "$a[b]" and it reports b as a T_STRING token. If I understand this correctly within strings it's permitted to use identifiers as string indices to avoid complex escaping. However outside of a string it's (rightfully) considered bad style.

If this is correct T_STRING is ALWAYS an identifier and "$a[b]" is just a special case where it's ok to use an identifier as a string index.
 [2010-10-19 06:15 UTC] kalle@php.net
Automatic comment from SVN on behalf of kalle
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=304494
Log: Fixed bug #52526 (Documentation for T_STRING implying bad programming style)
 [2010-10-19 06:15 UTC] kalle@php.net
-Status: Re-Opened +Status: Closed
 [2010-10-19 06:15 UTC] kalle@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=9e10c49739b8f49cb747d0c0a46ca049943e7e34
Log: Fixed bug #52526 (Documentation for T_STRING implying bad programming style)
 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d9c35b65d163cf11ebeeb907038a708c3a396b1a
Log: Fixed bug #52526 (Documentation for T_STRING implying bad programming style)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 25 14:00:02 2025 UTC