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

homelectsexamshws
D2Lbreeze (snow day)

lect02a-php-types
ch02: php types

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


Running your php programs:
  1. First run them on the server, using php from the command-line: php myfile.php. If you have syntax error, it will give you a line-number
    (as opposed to running via php.radford.edu, which will just quit w/o any output).
  2. Start your file with the following:
    <?php
    ini_set('display_errors', 'stderr');
    ini_set('display_startup_errors', true);
    error_reporting(E_ALL|E_STRICT);
    ?>
    
    Be aware though:
    • Of course, you want to put these right near the start of your file. It doesn't do good to turn on error-reporting on line 20, if you first have an error on line 10!
    • Calling ini_set has no effect on the current php process — it will only effect any files you include. (But that's enough reason to do it.)
    • For php 5.4, E_ALL already subsumes E_STRICT. However
      php.radford.edu
      is running php 5.3.

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

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

5 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 2013.Feb.08 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme