php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63959 Class constant assignment doesn't make sense
Submitted: 2013-01-10 11:00 UTC Modified: 2013-01-11 00:46 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: kevin at happycactus dot nl Assigned:
Status: Duplicate Package: Variables related
PHP Version: 5.4.10 OS: Windows Server 2012 Standard
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 + 41 = ?
Subscribe to this entry?

 
 [2013-01-10 11:00 UTC] kevin at happycactus dot nl
Description:
------------
We have to work around certain unnecessary limitations regarding class constants.
See 'Test script' for complete details on what bothers me (and other PHP 
developers)

Test script:
---------------
// Example 1: valid
const IMAGE_ROOT = '/www/public/img';

// Example 2: valid
define ('PUBLIC_ROOT', '/www/public');
define ('IMAGE_ROOT', PUBLIC_ROOT . '/img');
const FOO = IMAGE_ROOT;

// Example 3: invalid
define ('PUBLIC_ROOT', '/www/public');
const IMAGE_ROOT = PUBLIC_ROOT . '/img';

According to the manual:
"The value must be a constant expression, not (for example) a variable,
a property, a result of a mathematical operation, or a function call."

My question is: why is the concatenation of one or more CONSTANT values
prohibited in PHP? It doesn't have any added value, and even worse: makes
source code less readable because we have to clutter it with defined named constants or replace them with static properties as means of a workaround.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-11 00:46 UTC] aharvey@php.net
Duplicate of request #30177.
 [2013-01-11 00:46 UTC] aharvey@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC