RU beehive logo ITEC dept promo banner
ITEC 325
2012spring
ibarland

homelectsexamshws
D2Lbreeze (snow day)

lect02b-php-types
ch02: php types

From PHP Visual Quickstart Guide by Larry Ullman
Originally based on notes by Jack Davis (jcdavis@radford.edu)


1      

2 Well, “just like in other Algol-based syntaxes.”      

3 Well, “reasonably fully parenthesize” — the precedence rules are designed to make operators like function call, array-lookup, field-lookup etc. work as expected. Precedence between arithmetic is not really the purpose.      

4 So $x = false || true; is find; it means So $x = (false || true);, and $x gets the value true. But $x = false OR true; means ($x = false) OR true;, which means $x gets false but the entire line returns true if used in some bigger context. (Btw, using the result of assignment in a bigger context is rarely a good idea; it's a holdover from more primitive I/O libraries that didn't have any peek/hasNext functionality.)
Bottom line: use && and ||, and use parentheses if you need some unusual precedence.      

homelectsexamshws
D2Lbreeze (snow day)


©2012, Ian Barland, Radford University
Last modified 2012.May.31 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme