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

homelectshws
D2Lbreeze (snow day)

lect06-php-types
ch02: php types

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


1 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 operators isn't the true purpose of precedence rules — they're so that you can let the other operators have a convenient, easy-to-read, easy-to-write syntax that doesn't get in the way of what you're trying to write.      

2 A similar term is “transclusion”, including one document inside another, like      

3 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.      

4 In php, a "global" variable is one that can be used anywhere, but to use it you must first explicitly import it inside a function:

$n = 17

function f($x) {
  global $n; // this line required to use $n inside this function.
  return $x + $n;
  }
          
     

homelectshws
D2Lbreeze (snow day)


©2014, Ian Barland, Radford University
Last modified 2015.Feb.09 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.