php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #6992 string "NULL" equals 0
Submitted: 2000-10-03 08:01 UTC Modified: 2000-10-10 08:39 UTC
From: david@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0 Latest CVS (03/10/2000) OS: Linux
Private report: No CVE-ID: None
 [2000-10-03 08:01 UTC] david@php.net
The text string "NULL" compares equal to 0. This is rubbish. The string is not empty. NULL may compare equal to 0. The string containing NULL should not.

[david@serena php4]$ ./php
<?
if ("NULL" == 0)
  echo "This is not good.";
?>
X-Powered-By: PHP/4.0.3RC1
Content-type: text/html

This is not good.

./configure --with-config-file-path=`pwd`

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-03 08:39 UTC] waldschrott@php.net
hehe, you?ve been fooled by auto-conversion... :)

<?php echo "CONERTMETOZERO"==0; ?>

See? Perhaps we need some chapter about auto-conversion? Telling which rules apply comparing 'AZ' against 'A' or 'AAT' or 0 or whatever
 [2000-10-03 08:43 UTC] waldschrott@php.net
just saw this issue is already covered by documenation, but hairy things like "AZ"<="AAZ" not
 [2000-10-04 01:16 UTC] david@php.net
This is in the context of a db insert query:

($var == "NULL" ? "NULL" : "'$var'")

where the text string NULL is used to signify null.

Having to use === in this instance sucks bigtime. Why is PHP so deviant in this behaviour? Can we fix it?

Maybe I should be using (is_int($var) == true and ($var === "NULL") != false). Yeah.

Why would I ever want to compare a text string to zero? Bleurgh!
 [2000-10-04 01:30 UTC] waldschrott@php.net
($var === NULL ? "NULL" : "'$var'")
should do the job


 [2000-10-10 08:39 UTC] stas@php.net
OK, this is how PHP works, so it's clearly not a bug. Submit a feature request or use === if you don't like it.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Jun 13 02:00:02 2026 UTC