PageRenderTime 48ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/php/proxy/runme.php

#
PHP | 68 lines | 41 code | 15 blank | 12 comment | 0 complexity | e819359d8a5e626c952e8f23b265dd7a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  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. include("example.php");
  6. # ----- Object creation -----
  7. print "Creating some objects:\n";
  8. $c = example::CircleFactory(10);
  9. print " Created circle \$c with area ". $c->area() ."\n";
  10. $s = new Square(10);
  11. print " Created square \$s\n";
  12. # ----- Access a static member -----
  13. print "\nA total of " . Shape::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. $c->x = 20;
  19. $c->y = 30;
  20. $s->x = -10;
  21. $s->y = 5;
  22. print "\nHere is their current position:\n";
  23. print " Circle = (" . $c->x . "," . $c->y . ")\n";
  24. print " Square = (" . $s->x . "," . $s->y . ")\n";
  25. # ----- Call some methods -----
  26. print "\nHere are some properties of the shapes:\n";
  27. foreach (array($c,$s) as $o) {
  28. print " ".get_class($o)." \$o\n";
  29. print " x = " . $o->x . "\n";
  30. print " y = " . $o->y . "\n";
  31. print " area = " . $o->area() . "\n";
  32. print " perimeter = " . $o->perimeter() . "\n";
  33. }
  34. # Need to unset($o) or else we hang on to a reference to the Square object.
  35. unset($o);
  36. # ----- Delete everything -----
  37. print "\nGuess I'll clean up now\n";
  38. # Note: this invokes the virtual destructor
  39. unset($c);
  40. $s = 42;
  41. print Shape::nshapes() . " shapes remain\n";
  42. print "Manually setting nshapes\n";
  43. Shape::nshapes(42);
  44. print Shape::get_nshapes() ." == 42\n";
  45. print "Goodbye\n";
  46. ?>