Page 233 - Beginning PHP 5.3
P. 233

Chapter 8: Objects

                               public function getArea() {
                                 return pow( $this- > _sideLength, 2 );
                               }
                             }

                             $myCircle = new Circle;
                             $myCircle- > setColor( “red” );
                             $myCircle- > fill();
                             $myCircle- > setRadius( 4 );
                             echo “ < h2 > My Circle < /h2 > ”;
                             echo “ < p > My circle has a radius of “ . $myCircle- > getRadius() . “. < /p > ”;
                             echo “ < p > It is “ . $myCircle- > getColor() . “ and it is “ . ( $myCircle- >
                             isFilled() ? “filled” : “hollow” ) . “. < /p > ”;
                             echo “ < p > The area of my circle is: “ . $myCircle- > getArea() . “. < /p > ”;

                             $mySquare = new Square;
                             $mySquare- > setColor( “green” );
                             $mySquare- > makeHollow();
                             $mySquare- > setSideLength( 3 );
                             echo “ < h2 > My Square < /h2 > ”;
                             echo “ < p > My square has a side length of “ . $mySquare- > getSideLength() .
                             “. < /p > ”;
                             echo “ < p > It is “ . $mySquare- > getColor() . “ and it is “ . ( $mySquare-
                                                                                                     >
                               isFilled() ? “filled” : “hollow” ) . “. <  /p > ”;
                             echo “ < p > The area of my square is: “ . $mySquare- > getArea() . “. < /p > ”;

                             ? >

                                 < /body >


                               < /html >


























                                     Figure 8 - 5

                                                                                                         195





                                                                                                      9/21/09   9:03:41 AM
          c08.indd   195
          c08.indd   195                                                                              9/21/09   9:03:41 AM
   228   229   230   231   232   233   234   235   236   237   238