[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)
|
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
|
2009-08-13: wsfulton
|
||||||
[PHP] std::vector wrappers overhaul. They no longer require the
|
[PHP] std::vector wrappers overhaul. They no longer require the
|
||||||
specialize_std_vector() macro. Added wrappers for capacity() and reserve().
|
specialize_std_vector() macro. Added wrappers for capacity() and reserve().
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ CXXSRCS = example.cxx
|
||||||
TARGET = example
|
TARGET = example
|
||||||
INTERFACE = example.i
|
INTERFACE = example.i
|
||||||
LIBS =
|
LIBS =
|
||||||
SWIGOPT = -noproxy
|
SWIGOPT =
|
||||||
|
|
||||||
all::
|
all::
|
||||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
# This file illustrates the low-level C++ interface
|
# This example illustrates how member variables are wrapped.
|
||||||
# created by SWIG. In this case, all of our C++ classes
|
|
||||||
# get converted into function calls.
|
|
||||||
|
|
||||||
require("example.php");
|
require("example.php");
|
||||||
|
|
||||||
# ----- Object creation -----
|
# ----- Object creation -----
|
||||||
|
|
||||||
print "Creating some objects:\n";
|
print "Creating some objects:\n";
|
||||||
$c = new_Circle(10);
|
$c = new Circle(10);
|
||||||
print " Created circle $c\n";
|
print " Created circle\n";
|
||||||
$s = new_Square(10);
|
$s = new Square(10);
|
||||||
print " Created square $s\n";
|
print " Created square\n";
|
||||||
|
|
||||||
# ----- Access a static member -----
|
# ----- 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 -----
|
# ----- 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
|
# Note: methods in the base class Shape are used since
|
||||||
# x and y are defined there.
|
# x and y are defined there.
|
||||||
|
|
||||||
Shape_x_set($c, 20);
|
$c->x = 20;
|
||||||
Shape_y_set($c, 30);
|
$c->y = 30;
|
||||||
Shape_x_set($s,-10);
|
$s->x = -10;
|
||||||
Shape_y_set($s,5);
|
$s->y = 5;
|
||||||
|
|
||||||
print "\nHere is their current position:\n";
|
print "\nHere is their current position:\n";
|
||||||
print " Circle = (" . Shape_x_get($c) . "," . Shape_y_get($c) . ")\n";
|
print " Circle = ({$c->x},{$c->y})\n";
|
||||||
print " Square = (" . Shape_x_get($s) . "," . Shape_y_get($s) . ")\n";
|
print " Square = ({$s->x},{$s->y})\n";
|
||||||
|
|
||||||
# ----- Call some methods -----
|
# ----- 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.
|
# invoke the appropriate virtual method on each object.
|
||||||
print "\nHere are some properties of the shapes:\n";
|
print "\nHere are some properties of the shapes:\n";
|
||||||
foreach (array($c,$s) as $o) {
|
foreach (array($c,$s) as $o) {
|
||||||
print " $o\n";
|
print " ". get_class($o) . "\n";
|
||||||
print " area = " . Shape_area($o) . "\n";
|
print " area = {$o->area()}\n";
|
||||||
print " perimeter = " . Shape_perimeter($o) . "\n";
|
print " perimeter = {$o->perimeter()}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----- Delete everything -----
|
# ----- Delete everything -----
|
||||||
|
|
||||||
print "\nGuess I'll clean up now\n";
|
print "\nGuess I'll clean up now\n";
|
||||||
|
|
||||||
# Note: this invokes the virtual destructor
|
# Note: this invokes the virtual destructor
|
||||||
#delete_Shape($c);
|
|
||||||
#delete_Shape($s);
|
|
||||||
$c = NULL;
|
$c = NULL;
|
||||||
$s = NULL;
|
$s = NULL;
|
||||||
|
|
||||||
|
|
@ -58,7 +54,7 @@ $s = NULL;
|
||||||
# the square.
|
# the square.
|
||||||
$o = NULL;
|
$o = NULL;
|
||||||
|
|
||||||
print nshapes() . " shapes remain\n";
|
print Shape::get_nshapes() . " shapes remain\n";
|
||||||
print "Goodbye\n";
|
print "Goodbye\n";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue