3 # This example illustrates how member variables are wrapped.
5 require("example.php");
7 # ----- Object creation -----
9 print "Creating some objects:\n";
11 print " Created circle\n";
13 print " Created square\n";
15 # ----- Access a static member -----
17 print "\nA total of " . Shape::get_nshapes() . " shapes were created\n";
19 # ----- Member data access -----
21 # Set the location of the object.
22 # Note: methods in the base class Shape are used since
23 # x and y are defined there.
30 print "\nHere is their current position:\n";
31 print " Circle = ({$c->x},{$c->y})\n";
32 print " Square = ({$s->x},{$s->y})\n";
34 # ----- Call some methods -----
36 # Notice how the Shape_area() and Shape_perimeter() functions really
37 # invoke the appropriate virtual method on each object.
38 print "\nHere are some properties of the shapes:\n";
39 foreach (array($c,$s) as $o) {
40 print " ". get_class($o) . "\n";
41 print " area = {$o->area()}\n";
42 print " perimeter = {$o->perimeter()}\n";
45 # ----- Delete everything -----
47 print "\nGuess I'll clean up now\n";
49 # Note: this invokes the virtual destructor
53 # and don't forget the $o from the for loop above. It still refers to
57 print Shape::get_nshapes() . " shapes remain\n";