php.net |  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
Votes:4
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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');
or
$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. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-17 12:42 UTC] jani@php.net
-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] krakjoe@php.net
-Status: Open +Status: Wont fix
 [2015-02-17 08:38 UTC] krakjoe@php.net
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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC