3 # This file illustrates the low-level C++ interface
4 # created by SWIG. In this case, all of our C++ classes
5 # get converted into function calls.
7 include("example.php");
9 # ----- Object creation -----
11 print "Creating some objects:\n";
12 $c = CircleFactory(10);
13 print " Created circle $c with area ". $c->area() ."\n";
15 print " Created square $s\n";
17 # ----- Access a static member -----
19 print "\nA total of " . Shape::nshapes() . " shapes were created\n";
21 # ----- Member data access -----
23 # Set the location of the object.
24 # Note: methods in the base class Shape are used since
25 # x and y are defined there.
32 print "\nHere is their current position:\n";
33 print " Circle = (" . $c->x . "," . $c->y . ")\n";
34 print " Square = (" . $s->x . "," . $s->y . ")\n";
36 # ----- Call some methods -----
38 print "\nHere are some properties of the shapes:\n";
39 foreach (array($c,$s) as $o) {
40 print " ".get_class($o)." $o\n";
41 print " x = " . $o->x . "\n";
42 print " y = " . $o->y . "\n";
43 print " area = " . $o->area() . "\n";
44 print " perimeter = " . $o->perimeter() . "\n";
47 # Need to unset($o) or else we hang on to a reference to the Square object.
50 # ----- Delete everything -----
52 print "\nGuess I'll clean up now\n";
54 # Note: this invokes the virtual destructor
58 print Shape::nshapes() . " shapes remain\n";
60 print "Manually setting nshapes\n";
64 print Shape::get_nshapes() ." == 42\n";