php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55447 Global constant declared as const parsed as class constant with token_get_all()
Submitted: 2011-08-18 13:35 UTC Modified: 2011-08-18 14:39 UTC
From: andre at neo-anime dot org Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3SVN-2011-08-18 (SVN) OS: Linux
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: andre at neo-anime dot org
New email:
PHP Version: OS:

 

 [2011-08-18 13:35 UTC] andre at neo-anime dot org
Description:
------------
As of PHP 5.3.0 global constants can be declared using the const keyword in 
addition to the define() function. However token_get_all() incorrectly recognizes 
the former as a class constant.

Test script:
---------------
<?php
define('BAR', FALSE);

Expected result:
----------------
T_OPEN_TAG
T_STRING
T_CONSTANT_ENCAPSED_STRING
T_WHITESPACE
T_STRING


Actual result:
--------------
T_OPEN_TAG
T_CONST
T_WHITESPACE
T_STRING
T_WHITESPACE
T_WHITESPACE
T_STRING

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-18 13:54 UTC] andre at neo-anime dot org
Test script should be

<?php
const BAR = FALSE;
 [2011-08-18 14:39 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-08-18 14:39 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The const keyword and the define() function work completely different. The const keyword is handled at compile time whereas define(), for the engine, is a regular function. Different tokens therefore are identifed as different code is generated internally, too.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC