php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stephan dot soller at helionweb dot de
New email:
PHP Version: OS:

 

 [2010-09-26 22:19 UTC] stephan dot soller at helionweb dot de
Description:
------------
The documentation page about the PHP parser tokens (http://php.net/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:
---------------
<?php

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\']"; ?>');
print("\n----------\n\n");
inspect_tokens('<?php function test(){} class Test(){ const test = 123; } ?>');

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-27 09:57 UTC] salathe@php.net
-Status: Open +Status: Duplicate
 [2010-09-27 09:57 UTC] salathe@php.net
See #52526
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC