php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #30177 Allow concatenating in class constant values
Submitted: 2004-09-21 12:31 UTC Modified: 2014-03-05 21:20 UTC
Votes:7
Avg. Score:4.4 ± 0.7
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: guth at fiifo dot u-psud dot fr Assigned: requinix (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: guth at fiifo dot u-psud dot fr
New email:
PHP Version: OS:

 

 [2004-09-21 12:31 UTC] guth at fiifo dot u-psud dot fr
Description:
------------
hello,

const is too restrictive in PHP.

I think it could be a good idea that the following code worked as expected.

If the constant is not defined, PHP could print a NOTICE and use the name of the constant instead.

Reproduce code:
---------------
<?

define("ROOT", $_SERVER['DOCUMENT_ROOT']);

class FIIFO {

	const PATH = ROOT."/path/to/this/class";



}
?>

Expected result:
----------------
As PATH is a constant,

(FIIFO::PATH == "/www/path/to/this/class") for example.



Actual result:
--------------
A parse error...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-28 12:46 UTC] jani@php.net
-Summary: Change for const +Summary: Allow concatenating in constant values -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Linux (mandrake 10) +Operating System: * -PHP Version: 5.0.1 +PHP Version: *
 [2010-12-29 12:23 UTC] jani@php.net
-Summary: Allow concatenating in constant values +Summary: Allow concatenating in class constant values
 [2013-07-04 00:44 UTC] minchuk dot john at gmail dot com
Is this a bug or by design?  This produces the same error.  

        define("ASDF", "5678");

        $qwer = "1234" . ASDF;          //works fine

        $dude = new dude();             //errors here

        class dude {
                public $numbs = "1234" . ASDF;  //error
        }
 [2014-03-05 20:32 UTC] narf at devilix dot net
This has been implemented in PHP 5.6

https://wiki.php.net/rfc/const_scalar_exprs
 [2014-03-05 21:20 UTC] requinix@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: requinix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 16:01:31 2024 UTC