Download presentation
Presentation is loading. Please wait.
Published byRuby Francis Modified over 9 years ago
1
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1 Wiley and the book authors, 2002 PHP Bible Chapter 15: Basic PHP Gotchas
2
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition2 Wiley and the book authors, 2002 Summary Installation-related problems Blank and incomplete pages Parse errors Permissions problems Unbound variables Function problems Math problems
3
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition3 Wiley and the book authors, 2002 Installation-related problems Of course none of these problems will appear on the class' webserver, we'll go over some of the more common ones Symptom: Text of file displayed in browser window If your seeing your PHP script instead of the output HTML, check that you are accessing the site by http rather than the file system (e.g. http://localhost/mypage.php instead of file:/home/mypage.php) Symptom: PHP blocks showing up as text Filename extensions used for PHP are not associated to the PHP engine or you didn't give the file a PHP extension (e.g..php) Symptom: Server or host not found/Page cannot be displayed DNS or web-server configuration issue. Try pinging the host by name & IP. If the name doesn't resolve but the IP does, it's a DNS issue. If the name resolves & pings, it's a web-server config issue where the server is probably not bound correctly to port 80
4
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition4 Wiley and the book authors, 2002 Rendering problems Symptom: Totally blank page Probably an HTML problem where you are not outputting the proper HTML tags. Try viewing the source in the browser to see what errant code was output Symptom: Document contains no data PHP module may not be working correctly (try browsing another page in the same directory). Your code may not be outputting any HTML. Your PHP may be crashing before output can be generated (insert some print statements throughout your code so you can see where it is failing). Symptom: Incomplete or unintended page Usually bad HTML (view your HTML output, save it to a file, and run it through an HTML validation tool) Symptom: PHP code showing up in browser May be missing a PHP start tag
5
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition5 Wiley and the book authors, 2002 Failures to load page Symptom: Page cannot be found If other things are working, you are probably misspelling the file name (capitalization must match, spaces, etc.) Symptom: Failed opening [file] for inclusion Misspelled included file name, incorrect directory permissions, path not set correctly for include files in php.ini
6
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition6 Wiley and the book authors, 2002 Parse errors Symptom: Parse error message (e.g. Parse error: parse error in myfile.php on line 30) Category of errors arising from mistyped or syntactically incorrect PHP code Line number may or may not have Missing semicolon Missing dollar sign preceding a variable name Mode issues (failing to close a PHP section then trying to output HTML Unescaped quotes (trying to put a quote symbol into a string without putting a backslash in front of it) Unterminated strings (failing to close off a quoted string can result in parse errors located far away) Anything else
7
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition7 Wiley and the book authors, 2002 Unbound variables Symptom: Variable not showing up in print string Variable probably not assigned. Check spelling & capitalization Variable also may be out of scope. If accessing global variable from within a function, use the global construct Symptom: Numerical variable unexpectedly zero Same as above
8
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition8 Wiley and the book authors, 2002 Function problems Symptom: Call to undefined function Name may be misspelled, or function definition is missing If function is located in an included file, the included file may not have been found (switch to using require_once ) Declaring the function as a variable ( function $my_func() ) Using parenthesis in array indices ( $my_array(5) ) Symptom: Cannot redeclare function Two definitions exist with the same function name Using include or require instead of include_once or require_once Symptom: Wrong parameter count Too many arguments or too few when calling a function
9
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition9 Wiley and the book authors, 2002 Math problems Symptom: Division-by-zero warning Dividing by or using a function that divides by a variable that is unbound or which had been assigned a value of 0 Unexpected arithmetic result Check for unbound variables and precedence confusions. Add parentheses if you think precedence may be causing the problem Symptom: NaN or NAN Means Not a Number which is a misnomer. It is a number which has no value (not even 0), any equality tests with other numbers will return false (even when comparing it with the value NaN) Generally the result of a numeric, yet invalid value being passed into a PHP function (e.g. passing 45.0 into acos() ) Any equations where the NaN value is a part of the equation will result in a NaN value
10
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition10 Wiley and the book authors, 2002 Time-outs Any download can occasionally time out before a complete page can be delivered. However, this shouldn't be happening frequently on your local development server. If it does, you may have an issue that has nothing to do with slow Internet connections or server overload. Most "interesting" reason for a time-out is an infinite loop Moster "interesting" reason for a time-out is infinite recursion (function which calls itself without having a way of stopping the process) Can also be the result of resource requests timing out (e.g. running a query on a DB back-end which takes too long to return). Directives can be given to PHP in files which have long queries, etc. to wait longer for the query to return.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.