php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #49911 Allow using const keyword outside a class definition
Submitted: 2009-10-18 08:24 UTC Modified: 2015-03-21 20:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: admin at d9tx dot com Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: * 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: admin at d9tx dot com
New email:
PHP Version: OS:

 

 [2009-10-18 08:24 UTC] admin at d9tx dot com
Description:
------------
comparison const and define.
define() allows expressions as the value.
but const only allows scalar.

Reproduce code:
---------------
const FIRST_CONSTANT = __DIR__.DIRECTORY_SEPARATOR;
// parse error

define('SECOND_CONSTANT', __DIR__.DIRECTORY_SEPARATOR);
// this work

const THIRD_CONSTANT = SECOND_CONSTANT;
// this work too

Expected result:
----------------
const FIRST_CONSTANT = __DIR__.DIRECTORY_SEPARATOR;
// expected same define() work

define('SECOND_CONSTANT', __DIR__.DIRECTORY_SEPARATOR);
// this work

const THIRD_CONSTANT = SECOND_CONSTANT;
// this work too


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-28 12:52 UTC] jani@php.net
-Summary: new const keyword outside a class definition +Summary: Allow using const keyword outside a class definition -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: all +Operating System: * -PHP Version: 5.3.0 +PHP Version: *
 [2015-03-21 20:19 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2015-03-21 20:19 UTC] nikic@php.net
Supported since PHP 5.6.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 16:01:38 2025 UTC