php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67104 Behaviour of defining constants is inconsistent and misleading
Submitted: 2014-04-21 23:57 UTC Modified: 2019-05-09 09:55 UTC
Votes:4
Avg. Score:3.8 ± 1.6
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: ss23 at ss23 dot geek dot nz Assigned: nikic (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant 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: ss23 at ss23 dot geek dot nz
New email:
PHP Version: OS:

 

 [2014-04-21 23:57 UTC] ss23 at ss23 dot geek dot nz
Description:
------------
The current behaviour is very confusing.

Test script:
---------------
<?php

define('TRUE', false);

var_dump(true);
var_dump(TRUE);
var_dump(constant('TRUE'));
var_dump(constant('true'));

Expected result:
----------------
Anything but this. An E_ERROR (or even E_WARNING) on the initial define would be enough.

Actual result:
--------------
bool(true)
bool(true)
bool(false)
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-07 08:58 UTC] iam4webwork at hotmail dot com
The following result occurs for PHP4.3.0-5.1.2 (see http://3v4l.org/M1ZrQ#v430)

bool(true)
bool(false)
bool(false)
bool(true)

These results seem fine.  What changed and why? I agree that there sh/b s.thing in case s.one tries to override a built-in constant.
 [2018-09-12 23:58 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2018-09-12 23:58 UTC] nikic@php.net
This will be resolved in PHP 8 by https://wiki.php.net/rfc/case_insensitive_constant_deprecation. Redefinition checks for case-insensitive constants currently do not work correctly and will not be fixed until support is removed entirely.
 [2019-05-09 09:55 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-05-09 09:55 UTC] nikic@php.net
Now prints the following on PHP 8, as expected:

Notice: Constant TRUE already defined in /home/nikic/php-src/t011.php on line 2
bool(true)
bool(true)
bool(true)
bool(true)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 11:01:34 2025 UTC