Chapter 8 - Review

Output
Show all Hide all
1Toggle answer visibilityWhy must PHP scripts be run through a URL?

PHP is primarily a server side language. The processor that reads and translates the php script is installed on the web server that handles url requests. To see how a php script performs you must access it through a server, not merely just open the file in a browser window.

2Toggle answer visibilityWhat version of PHP are you using? What version of MySQL? What version of what Web server application are you using? On what operating system?

Local Development Server
PHP v5.4.4
MySQL v5.5.25a
Web Server: Apache v2.4.2
Operating System: Win32

Live Production Server
PHP v5.2.17
MySQL v5.5.33
Web Server: Apache v2.2.25
Operating System: Linux CentOS

3Toggle answer visibilityWhat debugging steps should you take if the rendered Web page doesn't look right in your Web browser?

If the rendered page is incorrectly displayed, view the source code to check if nested tags are closed appropriately. If the page is dynamically generated through php - you will have to make your corrections there. Using an online HTML validator is helpful in tracking down poorly formatted HTML. Open the page in multiple browsers to compare visually. Use Firebug or other browser specific development tools.

4Toggle answer visibilityDo you have display_errors enabled on your server? Why is enabling display_errors useful on development servers? Why is revealing errors a bad thing on production servers?

Checking phpinfo() and scrolling to the Core variables shows that display_errors is indeed 'ON' on my local development server. You want to make sure this is enabled to assist in the development process. Error checking helps to speed up troubleshooting and accuracy in web deployment. Always disable display_errors on live production servers to prevent sensitive information about your server from being displayed to any random Joe Internet User. (It's just plain rude and confusing too.)

5Toggle answer visibilityHow does the level of error_reporting affect PHP scripts? To what level of error_reporting is your PHP server set?

You can control the types of errors that get reported through PHP. Example Notices(alerts), Warnings(script continues),Errors(script ends) etc... My Local server is set to display ALL errors (in phpinfo() error_reporting is set to 32767 which is the same as E_ALL = All errors and warnings, as supported, except level E_STRICT prior to PHP 5.4.0.).

6Toggle answer visibilityWhat does the @ operator do?

The @ operator ignores error reporting for that particular expression to which it is prepended by setting the error reporting level to 0. If that line triggers an error, the error handler (or custom error handler) will still be called, but it will be called with an error level of 0. It can be used on function calls, variables, include calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth.

7Toggle answer visibilityWhat are the benefits of using your own error handling function? What impact does the error reporting level have when using your own error handling function?

By overriding the default error handling in php with a custom function you can be more specific about which errors are reported and what messages are displayed. The error reporting level is a value that corresponds to the type of error encountered. A call to error_reporting() will return the current error reporting level. If it is set to 0 , errors are suppressed, if set to -1 all errors are reported(equivalent to E_ALL as of PHP 5.4).

8Toggle answer visibilityHow can print or echo be used as debugging tools? Hint: There are many correct answers.

print() and echo() are very useful for outputting values to the screen during the development process. You can use them to track variable values throughout a script, display comments when certain logic blocks have completed, dump the content's of arrays and objects etc...

9Toggle answer visibility What is the method for fixing PHP SQL-MySQL bugs?

Troubleshooting errors in your PHP/MySQL script includes these and MORE...

  • Make sure you are editing the proper script/page. With includes - lots of different files can contribute to the creation of a page. Know where you are.
  • Make sure any changes to the document have been saved.
  • Make sure you are accessing the file through a url.
  • Know which versions of key software are running and the limitations/functionality of that partcular version.
  • Determine which part of your script is faulty...USER error, HTML/CSS, Javascript/AJAX, PHP coding , MySQL formatting/queries, DATA in the database
  • Utilize all error reporting that comes built into the software. This can help with any PHP Parse errors, misspellings, syntactical mistakes, function parameter errors etc...
  • Use quotes methodically and consistantly.
  • Use comments to deactivate portions of code to narrow down the error.
  • Output to screen arrays, objects, and variables to track their expected values.
  • Use echo() to add comments within complex logic blocks to indicate code execution.
  • Print out mysql queries to see if any errors in expression.
  • Run mysql queries in client or separate ap (like Workbench) to test result set and query variations.
  • Double check database permissions and user information are compatible.
  • Step away from the machine.

Source
<?php 
$review = array(
	1 => array(
		'q' =>'Why must PHP scripts be run through a URL?',
		'a' =>'<p>PHP is primarily a server side language. The processor that reads and translates the php script is installed on the web server 
		that handles url requests. To see how a php script performs you must access it through a server, not merely just open the file in a browser window.</p>'
	),
	2 => array(
		'q' =>'What version of PHP are you using? What version of MySQL? What version of what Web server application are you using?
		 On what operating system?',
		'a' =>'<p><b>Local Development Server</b><br />PHP v5.4.4 <br />MySQL v5.5.25a<br />Web Server: Apache v2.4.2<br />Operating System: Win32</p>
		<p><b>Live Production Server</b><br />PHP v5.2.17<br />MySQL v5.5.33<br />Web Server: Apache v2.2.25<br />Operating System: Linux CentOS</p>'
	),
	3 => array(
		'q' =>'What debugging steps should you take if the rendered Web page doesn\'t look right in your Web browser?',
		'a' =>'<p>If the rendered page is incorrectly displayed, view the source code to check if nested tags are closed appropriately. If the page is 
		dynamically generated through php - you will have to make your corrections there. Using an online HTML validator is helpful in tracking down poorly 
		formatted HTML. Open the page in multiple browsers to compare visually. Use Firebug or other browser specific development tools.</p>'
	),
	4 => array(
		'q' =>'Do you have display_errors enabled on your server? Why is enabling display_errors useful on development servers? 
		Why is revealing errors a bad thing on production servers?',
		'a' =>'<p>Checking phpinfo() and scrolling to the Core variables shows that display_errors is indeed \'ON\' on my local development server.
		You want to make sure this is enabled to assist in the development process. Error checking helps to speed up troubleshooting and accuracy
		in web deployment. Always disable display_errors on live production servers to prevent sensitive information about your server from 
		being displayed to any random Joe Internet User. (It\'s just plain rude and confusing too.)</p>'
	),
	5 => array(
		'q' =>'How does the level of error_reporting affect PHP scripts? To what level of error_reporting is your PHP server set?',
		'a' =>'<p>You can control the types of errors that get reported through PHP. Example Notices(alerts), Warnings(script continues),Errors(script ends) 
		etc... My Local server is set to display ALL errors (in phpinfo() error_reporting is set to 32767 which is the same as E_ALL = All 
			errors and warnings, as supported, except level E_STRICT prior to PHP 5.4.0.).</p>'
	),
	6 => array(
		'q' =>'What does the @ operator do?',
		'a' =>'<p>The @ operator ignores error reporting for that particular expression to which it is prepended by setting the error reporting
		 level to 0. If that line triggers an error, the error handler (or custom error handler) will still be called, but it will be called 
		 with an error level of 0. It can be used on function calls, variables, include calls, constants, and so forth. You cannot prepend it
		  to function or class definitions, or conditional structures such as if and foreach, and so forth.</p> '
	),
	7 => array(
		'q' =>'What are the benefits of using your own error handling function? What impact does the error reporting level have when using 
		your own error handling function?',
		'a' =>'<p>By overriding the default error handling in php with a custom function you can be more specific about which errors are reported 
		and what messages are displayed. The error reporting level is a value that corresponds to the type of error encountered. A call to error_reporting()
		 will return the current error reporting level. If it is set to 0 , errors are suppressed, if set to -1 all errors are reported(equivalent
		  to E_ALL as of PHP 5.4).</p>'
	),
	8 => array(
		'q' =>'How can print or echo be used as debugging tools? Hint: There are many correct answers.',
		'a' =>'<p><b>print()</b> and <b>echo()</b> are very useful for outputting values to the screen during the development process. You can 
		use them to track variable values throughout a script, display comments when certain logic blocks have completed, dump the content\'s of
		arrays and objects etc... </p>'
	),
	9 => array(
		'q' =>' What is the method for fixing PHP SQL-MySQL bugs?',
		'a' =>'<p>Troubleshooting errors in your PHP/MySQL script includes these and MORE...
		<ul>
		<li>Make sure you are editing the proper script/page. With includes - lots of different files can contribute to the creation of a page. Know where you are.</li>
		<li>Make sure any changes to the document have been saved.</li>
		<li>Make sure you are accessing the file through a url.</li>
		<li>Know which versions of key software are running and the limitations/functionality of that partcular version.</li>
		<li>Determine which part of your script is faulty...USER error, HTML/CSS, Javascript/AJAX, PHP coding , MySQL formatting/queries, DATA in the database</li>
		<li>Utilize all error reporting that comes built into the software. This can help with any PHP Parse errors, misspellings, syntactical mistakes, function parameter errors etc...</li>
		<li>Use quotes methodically and consistantly.</li>
		<li>Use comments to deactivate portions of code to narrow down the error.</li>
		<li>Output to screen arrays, objects, and variables to track their expected values.</li>
		<li>Use echo() to add comments within complex logic blocks to indicate code execution.</li>
		<li>Print out mysql queries to see if any errors in expression.</li>
		<li>Run mysql queries in client or separate ap (like Workbench) to test result set and query variations.</li>
		<li>Double check database permissions and user information are compatible.</li>
		<li>Step away from the machine.</li>
		</ul>
		</p>'
	)
);
include('templates/review.php');
?>