anyone care to explain the logic behind this output ....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	THIS CODE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

php -r '
$a = array(0, 1);
$b = array(1 => 0, 0 => 1);
var_dump($a < $b); // true
var_dump($a > $b); // true
var_dump($b < $a);
var_dump($b > $a);

echo "\n\$a:\n"; var_dump((bool)$a, (int)$a, (string)$a, intval($a), strval($a));
echo "\n\$b:\n"; var_dump((bool)$b, (int)$b, (string)$b, intval($b), strval($b));
'

	OUTPUTS (on php5.0.4):
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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

$a:
bool(true)
int(1)
string(5) "Array"

$b:
bool(true)
int(1)
string(5) "Array"

	WHICH MEANS THAT:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

one the one hand $a is greater than AND less than $b
but on the other hand casting $a OR $b to either a boolean,
integer or string results in the exact same value. ie:

php -r '
$a = array(0, 1); $b = array(1 => 0, 0 => 1);
var_dump( ((($a > $b) === ($b > $a)) === ((int)$a === (int)$b)) ); // WTF IT'S TRUE
'

weird? I think so - but then again I'd never test that array $a is
greater than array $b because this is meaningless to me (in what way is $a
greater - how is this quantified, what 'rules' determine 'greatness' in
this context?)

PS - changing the $b array to something else (anything else as far as i can tell)
causes the weirdness to not occur - which gives me the impression this could be a bug,
anyone else get this impression? for instance try changing the second line of
the code above to (merely switching the order or the defined array elements):

$b = array(0 => 1, 1 => 0);

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux