|
home—lects—hws
D2L—breeze (snow day)
<?php error_reporting(E_ALL|E_STRICT); ini_set('display_errors', 'stderr'); ini_set('display_startup_errors', true); ?> |
Reason: Before the first line of your program is run, php parses your entire file. If you have a missing semicolon on line 20, then line 1 will never even be run.
Solutions:
In practice, I do both (a) and (c).php.radford.eduis running php 5.3.
As we saw,
we can combine values (to use as an argument to
See also various error functions.
We can shorten silly-page_php.txt
to
silly-page-v2_php.txt.
(Self-quiz: Why can't I do a show-source of silly-page.php, to see the php code?)
Compare echoing “
"hello" . 17 'hello' "he'llo" 'he"llo' $myName = "Ian" "hello, $myName.\nBye." 'hello, $myName.\nBye' strlen("hi\n") strlen('hi\n') |
Take-away: I recommend using
Note: Arguably, php, with all its flaws, owes its success entirely to: (a) that variable-substitution, and (b) the convention that anything not inside a php processing-instruction should be literal output. (FWIW, a better way to blend code with large amoutns of literal-text-data is racket's “scribble” syntax: it nests better, and generalizes better.)
xhtml : Even though original HTML doesn't require the following, they are best practices, and they are required for this class:
The most common (non-X)HTML example using improperly nested tags is <p>, which (in HTML) doesn't need to be closed; the browser auto-closes the tag when it reaches the next <p> (or more precisely: when it reaches the next block-level open-tag, or a close-tag which is terminating the enclosing block, e.g. if the paragraph was already inside an itemized list).
Browsers tend to go to great lengths to try to make sense of tag soup; just because a page looks fine in your browser doesn't mean it's legal. The result is that many people learned their HTML by doing a show-source on bad, illegal examples, and then propagating that bad HTML, and never realizing it because most browsers still did something reasonable (although the details of how a browser handled bad HTML are of course entirely non-standard).
Important: In HTML (and enforced by most modern browsers), you can only use the self-closing tag, for those tags which never are allowed a body. For tags that may or may not have a body (notably:script ), you cannot use the self-closing version even when you want an empty body. There is no good reason for this!
- <hr />— fine;
hr never has a body.- <img src="foo.jpg" />— fine;
img never has a body.- <script type="text/javascript" src="foo.jpg"></script>— fine.
- <script type="text/javascript" >callSomeFunction();</script>— fine.
- <script type="text/javascript" src="foo.jpg" />— BAD; a browser may ignore the tag entirely!, which is an annoyingly difficult bug to track down.
See also: xhtml.com/en/future/x-html-5-versus-xhtml-2/.
1Later, we'll have php programs that only run in response to a form-submission.
You can still run these from the command-line:
make an test-file which initializes an array named
2A best practice…and yet: ugh! ↩
home—lects—hws
D2L—breeze (snow day)
©2014, Ian Barland, Radford University Last modified 2014.Oct.06 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |