runme.php4 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. # This file illustrates the low-level C++ interface
  3. # created by SWIG. In this case, all of our C++ classes
  4. # get converted into function calls.
  5. require("example.php");
  6. # ----- Object creation -----
  7. print "Creating some objects:\n";
  8. $c = new_Circle(10);
  9. print " Created circle $c\n";
  10. $s = new_Square(10);
  11. print " Created square $s\n";
  12. # ----- Access a static member -----
  13. print "\nA total of " . nshapes() . " shapes were created\n";
  14. # ----- Member data access -----
  15. # Set the location of the object.
  16. # Note: methods in the base class Shape are used since
  17. # x and y are defined there.
  18. Shape_x_set($c, 20);
  19. Shape_y_set($c, 30);
  20. Shape_x_set($s,-10);
  21. Shape_y_set($s,5);
  22. print "\nHere is their current position:\n";
  23. print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n";
  24. print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
  25. # ----- Call some methods -----
  26. print "\nHere are some properties of the shapes:\n";
  27. foreach (array($c,$s) as $o) {
  28. print " $o\n";
  29. print " area = " . Shape_area($o) . "\n";
  30. print " perimeter = " . Shape_perimeter($o) . "\n";
  31. }
  32. # Notice how the Shape_area() and Shape_perimeter() functions really
  33. # invoke the appropriate virtual method on each object.
  34. # ----- Delete everything -----
  35. print "\nGuess I'll clean up now\n";
  36. # Note: this invokes the virtual destructor
  37. delete_Shape($c);
  38. delete_Shape($s);
  39. print nshapes() . " shapes remain\n";
  40. print "Goodbye\n";
  41. ?>