示例#1
0
     * 
     * @param float $price
     */
    protected function setPrice($price)
    {
        if (is_float($price) || is_int($price)) {
            $this->price = (double) $price;
        } else {
            throw new Exception($this->getModel() . "'s price must be a numeric value!");
        }
    }
}
//Creating new Vehicle objects
try {
    $car = new Vehicle("Chevy", "Colorado", "2015", 20120);
    echo $car->toString() . "<br />";
    //Commenting out the code that will flag an error.
    //$car2 = new Vehicle("Chevy", "Silverado", "2015", "4900o"); //has an OH instead of zero
    //echo $car2->toString() . "<br />";
} catch (Exception $ex) {
    echo "Error, " . $ex->getMessage() . "<br />";
}
?>
                </p>
            </div>
            
            <div>
                <h1>
                    8. Consider the following array:
                </h1>
                <code>