php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67334 I can change the constant value using define method.
Submitted: 2014-05-23 11:35 UTC Modified: 2014-05-23 15:59 UTC
From: gangadhar dot kasim at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.28 OS: Windows
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: gangadhar dot kasim at gmail dot com
New email:
PHP Version: OS:

 

 [2014-05-23 11:35 UTC] gangadhar dot kasim at gmail dot com
Description:
------------

If I pass the optional third parameter in DEFINE method as TRUE, it is allowing me to override the existing value of a constant. This is not the expected behavior as constant's value should not be changed once it is declared.  

Test script:
---------------
define("GREETING", "Hello you.",true);
echo GREETING;  // outputs "Hello you." 
echo "before changing the constant value <br/>"; //before changing the constant value

define("GREETING", "sample value.");
echo GREETING; // outputs "sample value."
echo "<br/>";


Expected result:
----------------
constant's value should not be changed once it is declared.

Actual result:
--------------
it is allowing me to override the existing value of a constant.   

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 15:59 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-05-23 15:59 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is weird (and certainly a misfeature), but documented: case insensitive constant names are stored in lowercase, so internally, greeting and GREETING are different constants and hence an error isn't generated.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Feb 08 19:00:02 2026 UTC