note 87625 modified in function.define by danbrown

From: Date: Sat, 13 Dec 2008 19:26:57 +0000
Subject: note 87625 modified in function.define by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148132@lists.php.net to get a copy of this message
I'm running PHP Version 5.2.5 under Linux. And I just found out about something puzzling with the define() statement. Comparing a defined constant with an int always returns true. Here is the example code: <?php define('myDefinedName', 'stephane'); $myConstantName = myDefinedName; //$name = "0"; // Behaves as expected $name = 0; // Behaves contrary to expectation print("<br>myConstantName $myConstantName"); print("<br>name $name"); if ($name == myDefinedName) { print("<br>My name $name is (but should not be) equal to my defined name " . myDefinedName); } if ($name == $myConstantName) { print("<br>My name $name is (but should not be) equal to my constant name " . myConstantName); } ?> --was-- I'm running PHP Version 5.2.5 under Linux. And I just found out about something puzzling with the define() statement. Comparing a defined constant with an int always returns true. Here is the example code: define('myDefinedName', 'stephane'); $myConstantName = myDefinedName; //$name = "0"; // Behaves as expected $name = 0; // Behaves contrary to expectation print("<br>myConstantName $myConstantName"); print("<br>name $name"); if ($name == myDefinedName) { print("<br>My name $name is (but should not be) equal to my defined name " . myDefinedName); } if ($name == $myConstantName) { print("<br>My name $name is (but should not be) equal to my constant name " . myConstantName); } http://php.net/manual/en/function.define.php

« previous php.notes (#148132) next »