Hi!
Trying to learn PHP *well*, I've bogged down on table 15-5 in
http://www.php.net/manual/en/language.operators.comparison.php - it claims to
describe comparisons between different types, but then has a lot of missing
combinations, some internal clashes, a few bits which leave me in doubt, and
then *does* cover most of the same-type comparisons at various levels of
explicitness.
I've been sorting out other doubts about the language by writing test scripts,
but this would need to many tests to be practical: so the help of someone
already familiar with this would be appreciated.
Also, the results could be useful to others in the community.
SO - the table below is my best interpretation of 15-5, plus some notes on
explicit doubts. Assistance in completing/correcting the table would be
appreciated!
-- Kit Lester
[You'll need to view the following in a fixed width font.]
| null | boolean ! string | res'ce or | array ! object
! ! ! ! numeric ! !
---------+------+---------+------------+-----------+-------+------------
null | same | ! casts null | ! !
| | ! to "" | ! !
---------+------+---------+------------+-----------+-------+------------
null | same ! cast both operands to boolean, then FALSE<TRUE
---------+------+---------+------------+-----------+-------+------------
boolean | convert operand 2 to boolean then FALSE<TRUE
---------+------+---------+------------+-----------+-------+------------
string ! ! ! numeric or !
! ! ! lexic !
! ! ! compare ?? !
---------+------+---------+------------+-----------+-------+------------
string | ! ! cast str | cast str | !
resource | ! ! /res to ! /res to ! !
or | ! ! numeric, ! numeric, ! !
numeric | ! ! then ! then ! !
! ! ! "usual" ! "usual" ! !
---------+------+---------+------------+-----------+-------+------------
array ! array 1st operand is always greater (except ar vs ar???)
---------+------+---------+------------+-----------+-------+------------
object ! object 1st operand is always greater ! PHP4 != PHP5
---------+------+---------+------------+-----------+-------+------------
TABLE 15-5 CLAIMS IT IS FOR "DIFFERENT" OPERAND TYPES
-- but then explicity covers string vs string (twice?), str/res/num vs
str/res/num and obj vs obj
-- implicitly might be covering bool vs bool array vs array
leaving only null vs null uncovered... :-)
QUERIES IN THE TABLE:
-- "numeric or lexic comparison" presimably means that if both strings are
numeric, they are cast to numeric and compared -- but (1) what is a
"numeric" string? - one that starts with + - or a digit, so that trailing
non-numeric data is ignored? so "115 Somestreet"=="115 Anotherstreet"?
(2) what of the case where only one string is "numeric"?
-- does array-vs-anything cover array-vs-array? isn't a-vs-a special?
CLASHES (i.e. appear twice):
-- null op string
-- string op string (assume the explicit string vs string overrides the
string-etc vs string etc?)
-- does reources resource cast to numeric? oris that excluded from that
entry? or does it matter?
LOTTA GAPS...
Lycos email has now 300 Megabytes of free storage... Get it now at mail.lycos.co.uk
