[PHP] Update the PHP "class" example to work with PHP5 and use
modern wrapping features. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11565 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e125ce326d
commit
1b42d9dde1
3 changed files with 22 additions and 22 deletions
|
|
@ -1,6 +1,10 @@
|
|||
Version 1.3.40 (in progress)
|
||||
============================
|
||||
|
||||
2009-08-14: olly
|
||||
[PHP] Update the PHP "class" example to work with PHP5 and use
|
||||
modern wrapping features.
|
||||
|
||||
2009-08-13: wsfulton
|
||||
[PHP] std::vector wrappers overhaul. They no longer require the
|
||||
specialize_std_vector() macro. Added wrappers for capacity() and reserve().
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ CXXSRCS = example.cxx
|
|||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS =
|
||||
SWIGOPT = -noproxy
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
|
|
|
|||
|
|
@ -1,22 +1,20 @@
|
|||
<?php
|
||||
|
||||
# This file illustrates the low-level C++ interface
|
||||
# created by SWIG. In this case, all of our C++ classes
|
||||
# get converted into function calls.
|
||||
# This example illustrates how member variables are wrapped.
|
||||
|
||||
require("example.php");
|
||||
|
||||
# ----- Object creation -----
|
||||
|
||||
print "Creating some objects:\n";
|
||||
$c = new_Circle(10);
|
||||
print " Created circle $c\n";
|
||||
$s = new_Square(10);
|
||||
print " Created square $s\n";
|
||||
$c = new Circle(10);
|
||||
print " Created circle\n";
|
||||
$s = new Square(10);
|
||||
print " Created square\n";
|
||||
|
||||
# ----- Access a static member -----
|
||||
|
||||
print "\nA total of " . nshapes() . " shapes were created\n";
|
||||
print "\nA total of " . Shape::get_nshapes() . " shapes were created\n";
|
||||
|
||||
# ----- Member data access -----
|
||||
|
||||
|
|
@ -24,14 +22,14 @@ print "\nA total of " . nshapes() . " shapes were created\n";
|
|||
# Note: methods in the base class Shape are used since
|
||||
# x and y are defined there.
|
||||
|
||||
Shape_x_set($c, 20);
|
||||
Shape_y_set($c, 30);
|
||||
Shape_x_set($s,-10);
|
||||
Shape_y_set($s,5);
|
||||
$c->x = 20;
|
||||
$c->y = 30;
|
||||
$s->x = -10;
|
||||
$s->y = 5;
|
||||
|
||||
print "\nHere is their current position:\n";
|
||||
print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n";
|
||||
print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
|
||||
print " Circle = ({$c->x},{$c->y})\n";
|
||||
print " Square = ({$s->x},{$s->y})\n";
|
||||
|
||||
# ----- Call some methods -----
|
||||
|
||||
|
|
@ -39,18 +37,16 @@ print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
|
|||
# invoke the appropriate virtual method on each object.
|
||||
print "\nHere are some properties of the shapes:\n";
|
||||
foreach (array($c,$s) as $o) {
|
||||
print " $o\n";
|
||||
print " area = " . Shape_area($o) . "\n";
|
||||
print " perimeter = " . Shape_perimeter($o) . "\n";
|
||||
}
|
||||
print " ". get_class($o) . "\n";
|
||||
print " area = {$o->area()}\n";
|
||||
print " perimeter = {$o->perimeter()}\n";
|
||||
}
|
||||
|
||||
# ----- Delete everything -----
|
||||
|
||||
print "\nGuess I'll clean up now\n";
|
||||
|
||||
# Note: this invokes the virtual destructor
|
||||
#delete_Shape($c);
|
||||
#delete_Shape($s);
|
||||
$c = NULL;
|
||||
$s = NULL;
|
||||
|
||||
|
|
@ -58,7 +54,7 @@ $s = NULL;
|
|||
# the square.
|
||||
$o = NULL;
|
||||
|
||||
print nshapes() . " shapes remain\n";
|
||||
print Shape::get_nshapes() . " shapes remain\n";
|
||||
print "Goodbye\n";
|
||||
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue