Back to DFS's Workshop Page
Back to Agenda Page


Hardsetting Data to Check a Script

In order to test a script, it is often most beneficial to hardset variables so that they contain known values. Obviously, this script is not intended for production purposes -- it does the same thing time after time.

We will use the area-of-a-triangle problem for this demonstration.

A PHP Script to Handle Hardset Information

The following code should be saved in a file called trihardsetCL.php.

<?php
// trihardsetCL.php
// This script illustrates how to process information
// hardset in a script for testing purposes

// Hardset the dimensions dimensions $b (base) and $h (height)
// of the triangle
$b = 5;
$h = 7;

echo "Calculating the Area of a Triangle\n";
// Print the base
echo "b is $b.\n";

// Print the height
echo "h is $h.\n";

// Calculate and print result
$A = $b * $h / 2;
echo "The area of a triangle with a base of $b and a height of $h is $A.\n";
?>

Notes


© 2005 DFStermole
Created: 30 Oct 05
Last Modified: 30 Oct 05