Page 216 - Beginning PHP 5.3
P. 216

Part II: Learning the Language

                    echo “ < /p > < p > Top speed! Slowing down... < br / > ”;


                    while ( $myCar- > brake() ) {
                      echo “Current speed: “ . $myCar- > getSpeed() . “ mph < br / > ”;
                    }


                    echo “ < /p > < p > Stopped! < /p > ”;

                    ? >

                       < /body >
                      < /html >









































                   Figure 8-2

                    H ow  I t  W orks
                  This script adds some useful behaviors to the  Car  class in the form of three methods:
                ❑       accelerate()  speeds up the car by 10 mph, returning  true  if successful. If the car is already at top
                    speed  —  100 mph  —  the car isn ’ t accelerated any further, and   accelerate()  returns  false


              178





                                                                                                      9/21/09   9:03:34 AM
          c08.indd   178                                                                              9/21/09   9:03:34 AM
          c08.indd   178
   211   212   213   214   215   216   217   218   219   220   221