|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #52927 T_STRING token used for function and class names but documented for strings
Submitted: 2010-09-26 22:19 UTC Modified: 2010-09-27 09:57 UTC
From: stephan dot soller at helionweb dot de Assigned:
Status: Duplicate Package: Documentation problem
PHP Version: 5.3.3 OS:
Private report: No CVE-ID: None
 [2010-09-26 22:19 UTC] stephan dot soller at helionweb dot de
The documentation page about the PHP parser tokens ( states that the T_STRING token is an "string array index inside string" with this example code: "$a['a']".

Instead of this the T_STRING token is used for general symbol names (e.g. functions, classes, interfaces, constants).

The attached CLI test script lists the tokens for the example code of the documentation ("$a['a']") and it does not contain any T_STRING tokens. The second test source code with a function, class and constant however contains three T_STRING tokens, one for each symbol name (fun, TestClass and tconst).

I'm using the Ubuntu 10.04 PHP package:

$ php -v
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010 13:49:46) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

It would be nice if the documentation can mention the correct use of T_STRING.

Test script:

function inspect_tokens($code){
	print('Tokens for code: ' . $code . "\n");
	$tokens = token_get_all($code);
	foreach($tokens as $token)
		print( (is_string($token) ? $token : token_name($token[0]) . ': ' . $token[1]) . "\n");

inspect_tokens('<?php $a = array("a" => 1); $s = "$a[\'a\']"; ?>');
inspect_tokens('<?php function test(){} class Test(){ const test = 123; } ?>');



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-27 09:57 UTC]
-Status: Open +Status: Duplicate
 [2010-09-27 09:57 UTC]
See #52526
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 20:01:24 2021 UTC