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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Wed Apr 08 15:01:26 2020 UTC