|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #10527 Declare constant variables
Submitted: 2001-04-27 12:37 UTC Modified: 2015-02-17 08:38 UTC
Avg. Score:3.0 ± 1.4
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: jnutzman at yahoo dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jnutzman at yahoo dot com
New email:
PHP Version: OS:


 [2001-04-27 12:37 UTC] jnutzman at yahoo dot com
PHP 4 doesn't seem to have the capability to define variables of all types as being constants. An example of this could be:

$stuff = (const)array('1','2');
$stuff = const($stuff);

An error would be generated if the script later tried to:
$stuff = array('3','2');

This is *not* the same as CONSTANTS like TRUE and FALSE.

This would be extremely useful with sessions, so other programmers don't clobber important session variables that shouldn't change. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-17 12:42 UTC]
-Summary: Declare variables as constants +Summary: Declare constant variables -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: Linux +Operating System: * -PHP Version: 4.0.4pl1 +PHP Version: *
 [2015-02-17 08:38 UTC]
-Status: Open +Status: Wont fix
 [2015-02-17 08:38 UTC]
I don't think a constant variable makes sense in principle.

We don't have the concept of a symbol in user land PHP.

In C (or others), where everything is a symbol, functions, classes, named variables, it makes sense for a symbol to be constant.

In PHP, we don't have symbols, we have constants, variables, classes, and functions, they are distinct and non-overlapping.

To change this would be a significant and complicated change, of the kind that requires and RFC.

I'm therefore going to mark this bug as won't fix, it can still be found if some future RFC requires it for reference.

Sorry about the wait :)
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Jul 05 01:03:36 2022 UTC