php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #38555 PHP treats undefined constants differently to variables
Submitted: 2006-08-23 02:21 UTC Modified: 2006-08-23 07:36 UTC
From: php at seven dot net dot nz Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.1.5 OS: Irrelevant
Private report: No CVE-ID: None
 [2006-08-23 02:21 UTC] php at seven dot net dot nz
Description:
------------
PHP evaluates an undefined constant as true, whereas it evaluates an undefined variable as false.

Reproduce code:
---------------
<?= TEST ? '1' : '0' ?><br />
<?= $test ? '1' : '0' ?><br />

Expected result:
----------------
Notice: Use of undefined constant TEST - assumed 'TEST' in test.php on line 1
0

Notice: Undefined variable: test in test.php on line 2
0

Actual result:
--------------
Notice: Use of undefined constant TEST - assumed 'TEST' in test.php on line 1
1

Notice: Undefined variable: test in test.php on line 2
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-23 06:53 UTC] tony2001@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


 [2006-08-23 07:36 UTC] php at seven dot net dot nz
Well it may not be a bug per se, but can you tell me why similar language constructs that are used in similar ways behave in an opposite way?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC