0% found this document useful (0 votes)
15 views15 pages

How To Test and Debug1

Uploaded by

dangcongbang978
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views15 pages

How To Test and Debug1

Uploaded by

dangcongbang978
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Chapter 6

How to test and debug


a PHP application

C6, Slide 1
Objectives

Applied
1. Test and debug your PHP applications.
2. Trace the execution of a PHP application with echo statements.
3. If you’re using an IDE like NetBeans, set breakpoints, step
through code, observe the changes in variables, and use the stack
trace.

C6, Slide 2
Objectives (continued)
Knowledge
1. Distinguish between testing and debugging.
2. Distinguish between syntax, runtime, and logic errors.
3. Describe the use of breakpoints and stepping through code when
you’re using an IDE like NetBeans for debugging.

C6, Slide 3
The Discount application with a logic error

C6, Slide 4
The goal of testing
 To find all errors before the application is put into production.
The goal of debugging
 To fix all errors before the application is put into production.
Three test phases
 Check the user interface to make sure that it works correctly.
 Test the application with valid input data to make sure the results
are correct.
 Test the application with invalid data or unexpected user actions.
Try to make the application fail.

C6, Slide 5
The three types of errors that can occur
 syntax errors
 runtime errors
 logic errors

C6, Slide 6
PHP code that contains errors
// validate the list price entry
if ( $list_price = NULL || $list_price = FALSE ) {
$error = "Please enter a valid number.';
} else {
$error = ''
}

C6, Slide 7
The PHP code that contains errors in
NetBeans

C6, Slide 8
Common syntax errors
 Misspelling keywords.
 Forgetting an opening or closing parenthesis, bracket, brace, or
comment character.
 Forgetting to end a PHP statement with a semicolon.
 Forgetting an opening or closing quotation mark.
 Not using the same opening and closing quotation mark.

Problems with variable names


 Misspelling or incorrectly capitalizing a variable name.
 Using a keyword as a variable name.

C6, Slide 9
Problems with values
 Not checking that a value is the right data type before processing it.
 Using one equals sign instead of two when testing for equality.

C6, Slide 10
PHP with echo statements
that trace the execution of the code
// calculate the future value
$future_value = $investment;
echo '$future_value: ' . $future_value . '<br>';
echo '$interest_rate: ' . $interest_rate . '<br>';
echo '$years: ' . $years . '<br>';
echo 'For loop for calculating future value is
starting...<br><br>';
for ($i = 1; $i <= $years; $i++) {
$future_value += $future_value * $interest_rate;
echo '$i: ' . $i . '<br>';
echo '$future_value: ' . $future_value . '<br>';
}

C6, Slide 11
The data displayed in a browser

C6, Slide 12
A code editor window with a breakpoint

C6, Slide 13
A debugging session with variables displayed

C6, Slide 14
A debugging session with a stack trace
displayed

C6, Slide 15

You might also like