Illogical PHP Logic

In algebra, after we learn the basic distributive, commutative, and associative properties, the transitive property of equality is usually next in the curriculum. For those of you who do not recall the terminology, the transitive property of equality says if $a == $b and $b == $n then $a == $n. Using this age old logic, you can prove FALSE == TRUE and 0 == 1 in PHP. Here is how:

[code]
$a = 0;
$b = "Hooray for PHP logic and dynamic type casting?";
var_dump(((FALSE == $a) == ($a == $b)) == ($b == TRUE));
var_dump((((0 == $a) == ($a == $b)) == ($b == TRUE) == (TRUE == 1));[/code]
Returns
bool(true)
bool(true)

Q.E.D

Note: I am comparing values not types. That being said, forgive me when I flame you for using PHP inappropriately. A string is NOT an integer and an integer is NOT a boolean. They should not be used as such.

Related posts:

  1. Tic Tac Toe A graphical Tic Tac Toe board using PHP-Gtk [code]#!/usr/local/bin/php -q...

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.