import source from 1.3.40
[external/swig.git] / php / class / runme.php
1 <?php
2
3 # This example illustrates how member variables are wrapped.
4
5 require("example.php");
6
7 # ----- Object creation -----
8
9 print "Creating some objects:\n";
10 $c = new Circle(10);
11 print "    Created circle\n";
12 $s = new Square(10);
13 print "    Created square\n";
14
15 # ----- Access a static member -----
16
17 print "\nA total of " . Shape::get_nshapes() . " shapes were created\n";
18
19 # ----- Member data access -----
20
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.
24
25 $c->x = 20;
26 $c->y = 30;
27 $s->x = -10;
28 $s->y = 5;
29
30 print "\nHere is their current position:\n";
31 print "    Circle = ({$c->x},{$c->y})\n";
32 print "    Square = ({$s->x},{$s->y})\n";
33
34 # ----- Call some methods -----
35
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";
43 }
44
45 # ----- Delete everything -----
46
47 print "\nGuess I'll clean up now\n";
48
49 # Note: this invokes the virtual destructor
50 $c = NULL;
51 $s = NULL;
52
53 # and don't forget the $o from the for loop above.  It still refers to
54 # the square.
55 $o = NULL;
56
57 print Shape::get_nshapes() . " shapes remain\n";
58 print "Goodbye\n";
59
60 ?>