diff --git a/CHANGES.current b/CHANGES.current
index 14f6fb4cb..6a372cb56 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.11 (in progress)
============================
+2016-11-30: olly
+ [PHP] Add support for PHP7. PHP5's C extension API has changed substantially
+ so you need to use -php7 to specify you want PHP7 compatible wrappers.
+ Fixes https://github.com/swig/swig/issues/571
+
2016-11-28: wsfulton
Fix %rename override of wildcard %rename for templates. For example:
diff --git a/Doc/Manual/Php.html b/Doc/Manual/Php.html
index 56a6ba530..fea70a9fa 100644
--- a/Doc/Manual/Php.html
+++ b/Doc/Manual/Php.html
@@ -49,19 +49,6 @@
-
-SWIG supports generating wrappers for PHP5. Support for PHP4 was removed
-in SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases,
-and won't even be patching critical security issues after 2008-08-08, so it
-doesn't make much sense for SWIG to continue to support PHP4 now. If you
-really need to continue to use PHP4, just stick with SWIG 1.3.36.
-
-
-
-Currently any PHP5 release should work, but we don't regularly test with
-PHP < 5.3.
-
-
In this chapter, we discuss SWIG's support of PHP. The PHP module
was extensively rewritten in release 1.3.26, and support for generating
@@ -70,7 +57,17 @@ of the features available in some of the other languages.
-In order to use this module, you will need to have a copy of the PHP5
+SWIG supports generating wrappers for PHP5 and PHP7. Support for PHP4 was removed
+in SWIG 1.3.37.
+
+
+
+Currently any PHP5 or PHP7 release should work, but we don't regularly test with
+PHP < 5.3.
+
+
+
+In order to use this module, you will need to have a copy of the PHP
include files to compile the SWIG generated files. If you installed
PHP from a binary package, you may need to install a "php-dev" or "php-devel"
package for these to be installed. You can find out where these files are
@@ -84,12 +81,13 @@ available.
-Would be used in the following way from PHP5:
+Would be used in the following way from PHP:
@@ -646,7 +644,7 @@ Member variables and methods are accessed using the -> operator.
The -noproxy option flattens the object structure and
generates collections of named functions (these are the functions
-which the PHP5 class wrappers call). The above example results
+which the PHP class wrappers call). The above example results
in the following PHP functions:
diff --git a/Doc/Manual/Preprocessor.html b/Doc/Manual/Preprocessor.html
index 8eaed7f4f..ab32f79c7 100644
--- a/Doc/Manual/Preprocessor.html
+++ b/Doc/Manual/Preprocessor.html
@@ -125,7 +125,9 @@ SWIGMZSCHEME Defined when using Mzscheme
SWIGOCAML Defined when using Ocaml
SWIGOCTAVE Defined when using Octave
SWIGPERL Defined when using Perl
-SWIGPHP Defined when using PHP
+SWIGPHP Defined when using PHP5 or PHP7
+SWIGPHP5 Defined when using PHP5
+SWIGPHP7 Defined when using PHP7
SWIGPIKE Defined when using Pike
SWIGPYTHON Defined when using Python
SWIGR Defined when using R
diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html
index ae489f574..77481f279 100644
--- a/Doc/Manual/SWIG.html
+++ b/Doc/Manual/SWIG.html
@@ -131,7 +131,8 @@ can be obtained by typing swig -help or swig
-ocaml Generate Ocaml wrappers
-octave Generate Octave wrappers
-perl Generate Perl wrappers
--php Generate PHP wrappers
+-php5 Generate PHP5 wrappers
+-php7 Generate PHP7 wrappers
-pike Generate Pike wrappers
-python Generate Python wrappers
-r Generate R (aka GNU S) wrappers
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 9b510274a..d10f0f9a2 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1116,7 +1116,57 @@ ruby_clean:
rm -f *.@OBJEXT@ *$(RUBY_SO)
##################################################################
-##### PHP ######
+##### PHP5 ######
+##################################################################
+
+PHP5 = @PHP5@
+PHP5_INCLUDE = @PHP5INC@
+PHP5_SO = @PHP5_SO@
+PHP5_SCRIPT = $(SRCDIR)$(RUNME).php
+
+# -------------------------------------------------------------------
+# Build a PHP5 dynamically loadable module (C)
+# -------------------------------------------------------------------
+
+php5: $(SRCDIR_SRCS)
+ $(SWIG) -php5 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
+ $(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP5_INCLUDE)
+ $(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP5_SO)
+
+# --------------------------------------------------------------------
+# Build a PHP5 dynamically loadable module (C++)
+# --------------------------------------------------------------------
+
+php5_cpp: $(SRCDIR_SRCS)
+ $(SWIG) -php5 -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
+ $(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP5_INCLUDE)
+ $(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP5_SO)
+
+# -----------------------------------------------------------------
+# Running a PHP5 example
+# -----------------------------------------------------------------
+
+php5_run:
+ $(RUNTOOL) $(PHP5) -n -q -d extension_dir=. -d safe_mode=Off $(PHP5_SCRIPT) $(RUNPIPE)
+
+# -----------------------------------------------------------------
+# Version display
+# -----------------------------------------------------------------
+
+php5_version:
+ $(PHP5) -v | head -n 1
+
+# -----------------------------------------------------------------
+# Cleaning the PHP5 examples
+# -----------------------------------------------------------------
+
+php5_clean:
+ rm -f *_wrap* *~ .~* example.php php_example.h
+ rm -f core @EXTRA_CLEAN@
+ rm -f *.@OBJEXT@ *$(PHP5_SO)
+
+##################################################################
+##### PHP7 ######
##################################################################
PHP = @PHP@
@@ -1129,7 +1179,7 @@ PHP_SCRIPT = $(SRCDIR)$(RUNME).php
# -------------------------------------------------------------------
php: $(SRCDIR_SRCS)
- $(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
+ $(SWIG) -php7 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
@@ -1138,7 +1188,7 @@ php: $(SRCDIR_SRCS)
# --------------------------------------------------------------------
php_cpp: $(SRCDIR_SRCS)
- $(SWIG) -php -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
+ $(SWIG) -php7 -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
diff --git a/Examples/php5/callback/Makefile b/Examples/php5/callback/Makefile
new file mode 100644
index 000000000..3a34106c3
--- /dev/null
+++ b/Examples/php5/callback/Makefile
@@ -0,0 +1,19 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php5_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
diff --git a/Examples/php5/callback/example.cxx b/Examples/php5/callback/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/php5/callback/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/php5/callback/example.h b/Examples/php5/callback/example.h
new file mode 100644
index 000000000..2a0194999
--- /dev/null
+++ b/Examples/php5/callback/example.h
@@ -0,0 +1,22 @@
+/* File : example.h */
+
+#include
+
+class Callback {
+public:
+ virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
+ virtual void run() { std::cout << "Callback::run()" << std::endl; }
+};
+
+
+class Caller {
+private:
+ Callback *_callback;
+public:
+ Caller(): _callback(0) {}
+ ~Caller() { delCallback(); }
+ void delCallback() { delete _callback; _callback = 0; }
+ void setCallback(Callback *cb) { delCallback(); _callback = cb; }
+ void call() { if (_callback) _callback->run(); }
+};
+
diff --git a/Examples/php5/callback/example.i b/Examples/php5/callback/example.i
new file mode 100644
index 000000000..cf61ef9d2
--- /dev/null
+++ b/Examples/php5/callback/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+/* turn on director wrapping Callback */
+%feature("director") Callback;
+
+%include "example.h"
+
diff --git a/Examples/php5/callback/index.html b/Examples/php5/callback/index.html
new file mode 100644
index 000000000..2a6cbdff9
--- /dev/null
+++ b/Examples/php5/callback/index.html
@@ -0,0 +1,19 @@
+
+
+SWIG:Examples:php5:callback
+
+
+
+
+
+SWIG/Examples/php5/callback/
+
+
+Implementing C++ callbacks in PHP5
+
+
+This example illustrates how to use directors to implement C++ callbacks in PHP5.
+
+
+
+
diff --git a/Examples/php5/callback/runme.php b/Examples/php5/callback/runme.php
new file mode 100644
index 000000000..2be71994f
--- /dev/null
+++ b/Examples/php5/callback/runme.php
@@ -0,0 +1,47 @@
+thisown = 0;
+$caller->setCallback($callback);
+$caller->call();
+$caller->delCallback();
+
+print "\n";
+print "Adding and calling a PHP callback\n";
+print "------------------------------------\n";
+
+# Add a PHP callback.
+
+$callback = new PhpCallback();
+$callback->thisown = 0;
+$caller->setCallback($callback);
+$caller->call();
+$caller->delCallback();
+
+# All done.
+
+print "php exit\n";
+
+?>
diff --git a/Examples/php5/check.list b/Examples/php5/check.list
new file mode 100644
index 000000000..fef3feba6
--- /dev/null
+++ b/Examples/php5/check.list
@@ -0,0 +1,19 @@
+# see top-level Makefile.in
+# (see also top-level configure.ac kludge)
+callback
+class
+constants
+cpointer
+disown
+enum
+extend
+funcptr
+overloading
+pointer
+pragmas
+proxy
+reference
+simple
+sync
+value
+variables
diff --git a/Examples/php5/class/Makefile b/Examples/php5/class/Makefile
new file mode 100644
index 000000000..8346a1dae
--- /dev/null
+++ b/Examples/php5/class/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php5_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
diff --git a/Examples/php5/class/example.cxx b/Examples/php5/class/example.cxx
new file mode 100644
index 000000000..046304519
--- /dev/null
+++ b/Examples/php5/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.cxx */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area() {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter() {
+ return 2*M_PI*radius;
+}
+
+double Square::area() {
+ return width*width;
+}
+
+double Square::perimeter() {
+ return 4*width;
+}
diff --git a/Examples/php5/class/example.h b/Examples/php5/class/example.h
new file mode 100644
index 000000000..0dff185b2
--- /dev/null
+++ b/Examples/php5/class/example.h
@@ -0,0 +1,34 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ }
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area() = 0;
+ virtual double perimeter() = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { }
+ virtual double area();
+ virtual double perimeter();
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { }
+ virtual double area();
+ virtual double perimeter();
+};
diff --git a/Examples/php5/class/example.i b/Examples/php5/class/example.i
new file mode 100644
index 000000000..fbdf7249f
--- /dev/null
+++ b/Examples/php5/class/example.i
@@ -0,0 +1,9 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
diff --git a/Examples/php5/class/runme.php b/Examples/php5/class/runme.php
new file mode 100644
index 000000000..99c253b46
--- /dev/null
+++ b/Examples/php5/class/runme.php
@@ -0,0 +1,60 @@
+x = 20;
+$c->y = 30;
+$s->x = -10;
+$s->y = 5;
+
+print "\nHere is their current position:\n";
+print " Circle = ({$c->x},{$c->y})\n";
+print " Square = ({$s->x},{$s->y})\n";
+
+# ----- Call some methods -----
+
+# Notice how the Shape_area() and Shape_perimeter() functions really
+# invoke the appropriate virtual method on each object.
+print "\nHere are some properties of the shapes:\n";
+foreach (array($c,$s) as $o) {
+ 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
+$c = NULL;
+$s = NULL;
+
+# and don't forget the $o from the for loop above. It still refers to
+# the square.
+$o = NULL;
+
+print Shape::nshapes() . " shapes remain\n";
+print "Goodbye\n";
+
+?>
diff --git a/Examples/php5/constants/Makefile b/Examples/php5/constants/Makefile
new file mode 100644
index 000000000..a05be202b
--- /dev/null
+++ b/Examples/php5/constants/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/constants/example.i b/Examples/php5/constants/example.i
new file mode 100644
index 000000000..0098a893a
--- /dev/null
+++ b/Examples/php5/constants/example.i
@@ -0,0 +1,26 @@
+/* File : example.i */
+%module example
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+/* The following statements also produce constants */
+%constant int iconst = 37;
+%constant double fconst = 3.14;
+
+
diff --git a/Examples/php5/constants/runme.php b/Examples/php5/constants/runme.php
new file mode 100644
index 000000000..cea06485f
--- /dev/null
+++ b/Examples/php5/constants/runme.php
@@ -0,0 +1,28 @@
+
diff --git a/Examples/php5/cpointer/Makefile b/Examples/php5/cpointer/Makefile
new file mode 100644
index 000000000..47e5ed9f9
--- /dev/null
+++ b/Examples/php5/cpointer/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/cpointer/example.c b/Examples/php5/cpointer/example.c
new file mode 100644
index 000000000..04dd08df0
--- /dev/null
+++ b/Examples/php5/cpointer/example.c
@@ -0,0 +1,16 @@
+/* File : example.c */
+
+void add(int *x, int *y, int *result) {
+ *result = *x + *y;
+}
+
+void sub(int *x, int *y, int *result) {
+ *result = *x - *y;
+}
+
+int divide(int n, int d, int *r) {
+ int q;
+ q = n/d;
+ *r = n - q*d;
+ return q;
+}
diff --git a/Examples/php5/cpointer/example.i b/Examples/php5/cpointer/example.i
new file mode 100644
index 000000000..c61d92858
--- /dev/null
+++ b/Examples/php5/cpointer/example.i
@@ -0,0 +1,31 @@
+/* File : example.i */
+%module example
+
+%{
+extern void add(int *, int *, int *);
+extern void sub(int *, int *, int *);
+%}
+
+/* This example illustrates a couple of different techniques
+ for manipulating C pointers */
+
+/* First we'll use the pointer library */
+extern void add(int *x, int *y, int *result);
+
+%include cpointer.i
+%pointer_functions(int, intp);
+
+/* Next we'll use some typemaps */
+
+%include typemaps.i
+extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
+
+/* Next we'll use typemaps and the %apply directive */
+
+//%apply int *OUTPUT { int *r };
+//extern int divide(int n, int d, int *r);
+
+
+
+
+
diff --git a/Examples/php5/cpointer/runme.php b/Examples/php5/cpointer/runme.php
new file mode 100644
index 000000000..22e8a681a
--- /dev/null
+++ b/Examples/php5/cpointer/runme.php
@@ -0,0 +1,47 @@
+
diff --git a/Examples/php5/disown/Makefile b/Examples/php5/disown/Makefile
new file mode 100644
index 000000000..063a0645f
--- /dev/null
+++ b/Examples/php5/disown/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/disown/example.cxx b/Examples/php5/disown/example.cxx
new file mode 100644
index 000000000..6393735e9
--- /dev/null
+++ b/Examples/php5/disown/example.cxx
@@ -0,0 +1,51 @@
+/* File : example.c */
+
+#include "example.h"
+#include
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+int Shape::get_nshapes() {
+ return nshapes;
+}
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+void Circle::set_radius( double r ) {
+ radius = r;
+}
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
+
+ShapeContainer::~ShapeContainer() {
+ iterator i=shapes.begin();
+ for( iterator i = shapes.begin(); i != shapes.end(); ++i ) {
+ delete *i;
+ }
+}
+
+void
+ShapeContainer::addShape( Shape *s ) {
+ shapes.push_back( s );
+}
diff --git a/Examples/php5/disown/example.h b/Examples/php5/disown/example.h
new file mode 100644
index 000000000..e9f96743f
--- /dev/null
+++ b/Examples/php5/disown/example.h
@@ -0,0 +1,50 @@
+/* File : example.h */
+
+#include
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ }
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+ static int get_nshapes();
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { }
+ ~Circle() { }
+ void set_radius( double r );
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { }
+ ~Square() { }
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class ShapeContainer {
+private:
+ typedef std::vector::iterator iterator;
+ std::vector shapes;
+public:
+ ShapeContainer() : shapes() {}
+ ~ShapeContainer();
+ void addShape( Shape *s );
+};
diff --git a/Examples/php5/disown/example.i b/Examples/php5/disown/example.i
new file mode 100644
index 000000000..599f162c5
--- /dev/null
+++ b/Examples/php5/disown/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%apply SWIGTYPE *DISOWN {(Shape *s)};
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/php5/disown/runme.php b/Examples/php5/disown/runme.php
new file mode 100644
index 000000000..d90b03a9d
--- /dev/null
+++ b/Examples/php5/disown/runme.php
@@ -0,0 +1,49 @@
+addShape($c);
+$container->addShape($s);
+
+# ----- Access a static member -----
+
+print "\nA total of " . Shape::nshapes() . " shapes were created\n";
+
+# ----- Delete by the old references -----
+# This should not truely delete the shapes because they are now owned
+# by the ShapeContainer.
+
+print "Delete the old references.";
+
+# Note: this invokes the virtual destructor
+$c = NULL;
+$s = NULL;
+
+print "\nA total of " . Shape::nshapes() . " shapes remain\n";
+
+# ----- Delete by the container -----
+# This should truely delete the shapes
+
+print "Delete the container.";
+$container = NULL;
+print "\nA total of " . Shape::nshapes() . " shapes remain\n";
+
+print "Goodbye\n";
+
+?>
diff --git a/Examples/php5/enum/Makefile b/Examples/php5/enum/Makefile
new file mode 100644
index 000000000..4483f781e
--- /dev/null
+++ b/Examples/php5/enum/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT = -noproxy
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/enum/example.cxx b/Examples/php5/enum/example.cxx
new file mode 100644
index 000000000..df7bb6328
--- /dev/null
+++ b/Examples/php5/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.cxx */
+
+#include "example.h"
+#include
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ if (s == Foo::IMPULSE) {
+ printf("speed = IMPULSE speed\n");
+ } else if (s == Foo::WARP) {
+ printf("speed = WARP speed\n");
+ } else if (s == Foo::LUDICROUS) {
+ printf("speed = LUDICROUS speed\n");
+ } else {
+ printf("speed = Unknown speed!\n");
+ }
+}
diff --git a/Examples/php5/enum/example.h b/Examples/php5/enum/example.h
new file mode 100644
index 000000000..525d62afc
--- /dev/null
+++ b/Examples/php5/enum/example.h
@@ -0,0 +1,13 @@
+/* File : example.h */
+
+enum color { RED, BLUE, GREEN };
+
+class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE, WARP, LUDICROUS };
+ void enum_test(speed s);
+};
+
+void enum_test(color c, Foo::speed s);
+
diff --git a/Examples/php5/enum/example.i b/Examples/php5/enum/example.i
new file mode 100644
index 000000000..abf254731
--- /dev/null
+++ b/Examples/php5/enum/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/php5/enum/runme.php b/Examples/php5/enum/runme.php
new file mode 100644
index 000000000..55b0bc4c3
--- /dev/null
+++ b/Examples/php5/enum/runme.php
@@ -0,0 +1,32 @@
+
diff --git a/Examples/php5/extend/Makefile b/Examples/php5/extend/Makefile
new file mode 100644
index 000000000..7f91fd56c
--- /dev/null
+++ b/Examples/php5/extend/Makefile
@@ -0,0 +1,19 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS = -lm
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/extend/example.cxx b/Examples/php5/extend/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/php5/extend/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/php5/extend/example.h b/Examples/php5/extend/example.h
new file mode 100644
index 000000000..ca1aed28f
--- /dev/null
+++ b/Examples/php5/extend/example.h
@@ -0,0 +1,56 @@
+/* File : example.h */
+
+#include
+#include
+#include
+#include
+#include
+
+class Employee {
+private:
+ std::string name;
+public:
+ Employee(const char* n): name(n) {}
+ virtual std::string getTitle() { return getPosition() + " " + getName(); }
+ virtual std::string getName() { return name; }
+ virtual std::string getPosition() const { return "Employee"; }
+ virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); }
+};
+
+
+class Manager: public Employee {
+public:
+ Manager(const char* n): Employee(n) {}
+ virtual std::string getPosition() const { return "Manager"; }
+};
+
+
+class EmployeeList {
+ std::vector list;
+public:
+ EmployeeList() {
+ list.push_back(new Employee("Bob"));
+ list.push_back(new Employee("Jane"));
+ list.push_back(new Manager("Ted"));
+ }
+ void addEmployee(Employee *p) {
+ list.push_back(p);
+ std::cout << "New employee added. Current employees are:" << std::endl;
+ std::vector::iterator i;
+ for (i=list.begin(); i!=list.end(); i++) {
+ std::cout << " " << (*i)->getTitle() << std::endl;
+ }
+ }
+ const Employee *get_item(int i) {
+ return list[i];
+ }
+ ~EmployeeList() {
+ std::vector::iterator i;
+ std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
+ for (i=list.begin(); i!=list.end(); i++) {
+ delete *i;
+ }
+ std::cout << "~EmployeeList empty." << std::endl;
+ }
+};
+
diff --git a/Examples/php5/extend/example.i b/Examples/php5/extend/example.i
new file mode 100644
index 000000000..c8ec32e09
--- /dev/null
+++ b/Examples/php5/extend/example.i
@@ -0,0 +1,15 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_vector.i"
+%include "std_string.i"
+
+/* turn on director wrapping for Manager */
+%feature("director") Employee;
+%feature("director") Manager;
+
+%include "example.h"
+
diff --git a/Examples/php5/extend/index.html b/Examples/php5/extend/index.html
new file mode 100644
index 000000000..32c6a4913
--- /dev/null
+++ b/Examples/php5/extend/index.html
@@ -0,0 +1,19 @@
+
+
+SWIG:Examples:php:extend
+
+
+
+
+
+SWIG/Examples/php/extend/
+
+
+Extending a simple C++ class in PHP
+
+
+This example illustrates the extending of a C++ class with cross language polymorphism.
+
+
+
+
diff --git a/Examples/php5/extend/runme.php b/Examples/php5/extend/runme.php
new file mode 100644
index 000000000..158683142
--- /dev/null
+++ b/Examples/php5/extend/runme.php
@@ -0,0 +1,76 @@
+getName() . " is a " . $e->getPosition() . "\n";
+printf("Just call her \"%s\"\n", $e->getTitle());
+print "----------------------\n";
+
+# Create a new EmployeeList instance. This class does not have a C++
+# director wrapper, but can be used freely with other classes that do.
+
+$list = new EmployeeList();
+
+# EmployeeList owns its items, so we must surrender ownership of objects
+# we add. This involves first clearing the ->disown member to tell the
+# C++ director to start reference counting.
+
+$e->thisown = 0;
+$list->addEmployee($e);
+print "----------------------\n";
+
+# Now we access the first four items in list (three are C++ objects that
+# EmployeeList's constructor adds, the last is our CEO). The virtual
+# methods of all these instances are treated the same. For items 0, 1, and
+# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls
+# getPosition which resolves in PHP. The call to getPosition is
+# slightly different, however, from the e.getPosition() call above, since
+# now the object reference has been "laundered" by passing through
+# EmployeeList as an Employee*. Previously, PHP resolved the call
+# immediately in CEO, but now PHP thinks the object is an instance of
+# class Employee (actually EmployeePtr). So the call passes through the
+# Employee proxy class and on to the C wrappers and C++ director,
+# eventually ending up back at the CEO implementation of getPosition().
+# The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+# method, which in turn calls getPosition(). This virtual method call
+# passes down through the C++ director class to the PHP implementation
+# in CEO. All this routing takes place transparently.
+
+print "(position, title) for items 0-3:\n";
+
+printf(" %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle());
+printf(" %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle());
+printf(" %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle());
+printf(" %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle());
+print "----------------------\n";
+
+# Time to delete the EmployeeList, which will delete all the Employee*
+# items it contains. The last item is our CEO, which gets destroyed as its
+# reference count goes to zero. The PHP destructor runs, and is still
+# able to call the getName() method since the underlying C++ object still
+# exists. After this destructor runs the remaining C++ destructors run as
+# usual to destroy the object.
+
+unset($list);
+print "----------------------\n";
+
+# All done.
+
+print "php exit\n";
+
+?>
diff --git a/Examples/php5/funcptr/Makefile b/Examples/php5/funcptr/Makefile
new file mode 100644
index 000000000..47e5ed9f9
--- /dev/null
+++ b/Examples/php5/funcptr/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/funcptr/example.c b/Examples/php5/funcptr/example.c
new file mode 100644
index 000000000..99583b72e
--- /dev/null
+++ b/Examples/php5/funcptr/example.c
@@ -0,0 +1,17 @@
+/* File : example.c */
+
+int do_op(int a, int b, int (*op)(int,int)) {
+ return (*op)(a,b);
+}
+
+int add(int a, int b) {
+ return a+b;
+}
+
+int sub(int a, int b) {
+ return a-b;
+}
+
+int mul(int a, int b) {
+ return a*b;
+}
diff --git a/Examples/php5/funcptr/example.h b/Examples/php5/funcptr/example.h
new file mode 100644
index 000000000..58989db79
--- /dev/null
+++ b/Examples/php5/funcptr/example.h
@@ -0,0 +1,7 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
diff --git a/Examples/php5/funcptr/example.i b/Examples/php5/funcptr/example.i
new file mode 100644
index 000000000..39390da27
--- /dev/null
+++ b/Examples/php5/funcptr/example.i
@@ -0,0 +1,15 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+/* Now install a bunch of "ops" as constants */
+%constant int (*ADD)(int,int) = add;
+%constant int (*SUB)(int,int) = sub;
+%constant int (*MUL)(int,int) = mul;
+
+
diff --git a/Examples/php5/funcptr/runme.php b/Examples/php5/funcptr/runme.php
new file mode 100644
index 000000000..712d4147c
--- /dev/null
+++ b/Examples/php5/funcptr/runme.php
@@ -0,0 +1,24 @@
+
+
diff --git a/Examples/php5/overloading/Makefile b/Examples/php5/overloading/Makefile
new file mode 100644
index 000000000..063a0645f
--- /dev/null
+++ b/Examples/php5/overloading/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/overloading/example.cxx b/Examples/php5/overloading/example.cxx
new file mode 100644
index 000000000..2f684f05c
--- /dev/null
+++ b/Examples/php5/overloading/example.cxx
@@ -0,0 +1,55 @@
+/* File : example.c */
+
+#include "example.h"
+#include
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+int Shape::get_nshapes() {
+ return nshapes;
+}
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
+
+const char *overloaded(int i) {
+ return "Overloaded with int";
+}
+
+const char *overloaded(double d) {
+ return "Overloaded with double";
+}
+
+const char *overloaded(const char * str) {
+ return "Overloaded with char *";
+}
+
+const char *overloaded( const Circle& ) {
+ return "Overloaded with Circle";
+}
+
+const char *overloaded( const Shape& ) {
+ return "Overloaded with Shape";
+}
diff --git a/Examples/php5/overloading/example.h b/Examples/php5/overloading/example.h
new file mode 100644
index 000000000..01d71dd70
--- /dev/null
+++ b/Examples/php5/overloading/example.h
@@ -0,0 +1,46 @@
+/* File : example.h */
+
+#include
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ }
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+ static int get_nshapes();
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { }
+ ~Circle() { }
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { }
+ ~Square() { }
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+const char *overloaded( int i );
+const char *overloaded( double d );
+const char *overloaded( const char * str );
+const char *overloaded( const Circle& );
+const char *overloaded( const Shape& );
+
diff --git a/Examples/php5/overloading/example.i b/Examples/php5/overloading/example.i
new file mode 100644
index 000000000..950d2549d
--- /dev/null
+++ b/Examples/php5/overloading/example.i
@@ -0,0 +1,8 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include "example.h"
diff --git a/Examples/php5/overloading/runme.php b/Examples/php5/overloading/runme.php
new file mode 100644
index 000000000..56d515138
--- /dev/null
+++ b/Examples/php5/overloading/runme.php
@@ -0,0 +1,58 @@
+x = 20;
+$c->y = 30;
+$s->x = -10;
+$s->y = 5;
+
+print "\nHere is their current position:\n";
+print " Circle = (" . $c->x . "," . $c->y . ")\n";
+print " Square = (" . $s->x . "," . $s->y . ")\n";
+
+# ----- Call some methods -----
+
+print "\nCall some overloaded methods:\n";
+foreach (array(1, 2.1, "quick brown fox", $c, $s) as $o) {
+ print " overloaded = " . overloaded($o) . "\n";
+}
+
+# Need to unset($o) or else we hang on to a reference to the Square object.
+unset($o);
+
+# ----- Delete everything -----
+
+print "\nGuess I'll clean up now\n";
+
+# Note: this invokes the virtual destructor
+unset($c);
+$s = 42;
+
+print Shape::nshapes() . " shapes remain\n";
+
+print "Goodbye\n";
+
+?>
diff --git a/Examples/php5/pointer/Makefile b/Examples/php5/pointer/Makefile
new file mode 100644
index 000000000..47e5ed9f9
--- /dev/null
+++ b/Examples/php5/pointer/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/pointer/example.c b/Examples/php5/pointer/example.c
new file mode 100644
index 000000000..3326dec3e
--- /dev/null
+++ b/Examples/php5/pointer/example.c
@@ -0,0 +1,16 @@
+/* File : example.c */
+
+void add(double *x, double *y, double *result) {
+ *result = *x + *y;
+}
+
+void sub(int *x, int *y, int *result) {
+ *result = *x - *y;
+}
+
+int divide(int n, int d, int *r) {
+ int q;
+ q = n/d;
+ *r = n - q*d;
+ return q;
+}
diff --git a/Examples/php5/pointer/example.i b/Examples/php5/pointer/example.i
new file mode 100644
index 000000000..1f0059406
--- /dev/null
+++ b/Examples/php5/pointer/example.i
@@ -0,0 +1,30 @@
+/* File : example.i */
+%module example
+
+%{
+extern void add(double *, double *, double *);
+extern void sub(int *, int *, int *);
+extern int divide(int, int, int *);
+%}
+
+/* This example illustrates a couple of different techniques
+ for manipulating C pointers */
+
+%include phppointers.i
+/* First we'll use the pointer library */
+extern void add(double *REF, double *REF, double *REF);
+
+/* Next we'll use some typemaps */
+
+%include typemaps.i
+extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
+
+/* Next we'll use typemaps and the %apply directive */
+
+//%apply int *OUTPUT { int *r };
+//extern int divide(int n, int d, int *r);
+
+
+
+
+
diff --git a/Examples/php5/pointer/runme.php b/Examples/php5/pointer/runme.php
new file mode 100644
index 000000000..e79b23810
--- /dev/null
+++ b/Examples/php5/pointer/runme.php
@@ -0,0 +1,35 @@
+
diff --git a/Examples/php5/pragmas/Makefile b/Examples/php5/pragmas/Makefile
new file mode 100644
index 000000000..a05be202b
--- /dev/null
+++ b/Examples/php5/pragmas/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS =
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/pragmas/example.i b/Examples/php5/pragmas/example.i
new file mode 100644
index 000000000..c7e8bf303
--- /dev/null
+++ b/Examples/php5/pragmas/example.i
@@ -0,0 +1,31 @@
+/* File : example.i */
+%module example
+
+%init{
+ zend_printf("This was %%init\n");
+}
+
+%minit{
+ zend_printf("This was %%minit\n");
+}
+
+%mshutdown{
+ zend_printf("This was %%shutdown\n");
+}
+
+%rinit{
+ zend_printf("This was %%rinit\n");
+}
+
+%rshutdown{
+ zend_printf("This was %%rshutdown\n");
+}
+
+%pragma(php) include="include.php";
+
+%pragma(php) code="
+# This code is inserted into example.php
+echo \"this was php code\\n\";
+"
+
+%pragma(php) phpinfo="php_info_print_table_start();"
diff --git a/Examples/php5/pragmas/include.php b/Examples/php5/pragmas/include.php
new file mode 100644
index 000000000..e19880a06
--- /dev/null
+++ b/Examples/php5/pragmas/include.php
@@ -0,0 +1,7 @@
+
diff --git a/Examples/php5/pragmas/runme.php b/Examples/php5/pragmas/runme.php
new file mode 100644
index 000000000..538548b6f
--- /dev/null
+++ b/Examples/php5/pragmas/runme.php
@@ -0,0 +1,5 @@
+
diff --git a/Examples/php5/proxy/Makefile b/Examples/php5/proxy/Makefile
new file mode 100644
index 000000000..063a0645f
--- /dev/null
+++ b/Examples/php5/proxy/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/proxy/example.cxx b/Examples/php5/proxy/example.cxx
new file mode 100644
index 000000000..94e4a7888
--- /dev/null
+++ b/Examples/php5/proxy/example.cxx
@@ -0,0 +1,43 @@
+/* File : example.c */
+
+#include "example.h"
+#include
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+int Shape::get_nshapes() {
+ return nshapes;
+}
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+void Circle::set_radius( double r ) {
+ radius = r;
+}
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
+
+Circle *CircleFactory( double r ) {
+ return new Circle(r);
+}
diff --git a/Examples/php5/proxy/example.h b/Examples/php5/proxy/example.h
new file mode 100644
index 000000000..0683f07f3
--- /dev/null
+++ b/Examples/php5/proxy/example.h
@@ -0,0 +1,43 @@
+/* File : example.h */
+
+#include
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ }
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+ static int get_nshapes();
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { }
+ ~Circle() { }
+ void set_radius( double r );
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { }
+ ~Square() { }
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+Circle *CircleFactory( double r );
+
diff --git a/Examples/php5/proxy/example.i b/Examples/php5/proxy/example.i
new file mode 100644
index 000000000..ce73746d0
--- /dev/null
+++ b/Examples/php5/proxy/example.i
@@ -0,0 +1,12 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+
+%newobject CircleFactory;
+%include "example.h"
+
diff --git a/Examples/php5/proxy/runme.php b/Examples/php5/proxy/runme.php
new file mode 100644
index 000000000..e70ab229f
--- /dev/null
+++ b/Examples/php5/proxy/runme.php
@@ -0,0 +1,68 @@
+area() ."\n";
+$s = new Square(10);
+print " Created square \$s\n";
+
+# ----- Access a static member -----
+
+print "\nA total of " . Shape::nshapes() . " shapes were created\n";
+
+# ----- Member data access -----
+
+# Set the location of the object.
+# Note: methods in the base class Shape are used since
+# x and y are defined there.
+
+$c->x = 20;
+$c->y = 30;
+$s->x = -10;
+$s->y = 5;
+
+print "\nHere is their current position:\n";
+print " Circle = (" . $c->x . "," . $c->y . ")\n";
+print " Square = (" . $s->x . "," . $s->y . ")\n";
+
+# ----- Call some methods -----
+
+print "\nHere are some properties of the shapes:\n";
+foreach (array($c,$s) as $o) {
+ print " ".get_class($o)." \$o\n";
+ print " x = " . $o->x . "\n";
+ print " y = " . $o->y . "\n";
+ print " area = " . $o->area() . "\n";
+ print " perimeter = " . $o->perimeter() . "\n";
+ }
+
+# Need to unset($o) or else we hang on to a reference to the Square object.
+unset($o);
+
+# ----- Delete everything -----
+
+print "\nGuess I'll clean up now\n";
+
+# Note: this invokes the virtual destructor
+unset($c);
+$s = 42;
+
+print Shape::nshapes() . " shapes remain\n";
+
+print "Manually setting nshapes\n";
+
+Shape::nshapes(42);
+
+print Shape::get_nshapes() ." == 42\n";
+
+print "Goodbye\n";
+
+?>
diff --git a/Examples/php5/reference/Makefile b/Examples/php5/reference/Makefile
new file mode 100644
index 000000000..063a0645f
--- /dev/null
+++ b/Examples/php5/reference/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/reference/example.cxx b/Examples/php5/reference/example.cxx
new file mode 100644
index 000000000..7ead7fbf6
--- /dev/null
+++ b/Examples/php5/reference/example.cxx
@@ -0,0 +1,49 @@
+/* File : example.cxx */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include "example.h"
+#include
+#include
+
+Vector operator+(const Vector &a, const Vector &b) {
+ Vector r;
+ r.x = a.x + b.x;
+ r.y = a.y + b.y;
+ r.z = a.z + b.z;
+ return r;
+}
+
+char *Vector::as_string() {
+ static char temp[512];
+ sprintf(temp,"Vector %p (%g,%g,%g)", (void *)this, x,y,z);
+ return temp;
+}
+
+VectorArray::VectorArray(int size) {
+ items = new Vector[size];
+ maxsize = size;
+ printf("VectorArray new: self=%p\n", (void *)this);
+}
+
+VectorArray::~VectorArray() {
+ printf("VectorArray delete: self=%p\n", (void *)this);
+ delete [] items;
+}
+
+Vector &VectorArray::operator[](int index) {
+ printf("VectorArray: read[%d] self=%p\n", index, (void *)this);
+ if ((index < 0) || (index >= maxsize)) {
+ printf("Panic! Array index out of bounds.\n");
+ exit(1);
+ }
+ return items[index];
+}
+
+int VectorArray::size() {
+ printf("VectorArray: size %d self=%p\n", maxsize, (void *)this);
+ return maxsize;
+}
diff --git a/Examples/php5/reference/example.h b/Examples/php5/reference/example.h
new file mode 100644
index 000000000..353b88835
--- /dev/null
+++ b/Examples/php5/reference/example.h
@@ -0,0 +1,22 @@
+/* File : example.h */
+
+class Vector {
+private:
+ double x,y,z;
+public:
+ Vector() : x(0), y(0), z(0) { }
+ Vector(double x, double y, double z) : x(x), y(y), z(z) { }
+ friend Vector operator+(const Vector &a, const Vector &b);
+ char *as_string();
+};
+
+class VectorArray {
+private:
+ Vector *items;
+ int maxsize;
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ Vector &operator[](int);
+ int size();
+};
diff --git a/Examples/php5/reference/example.i b/Examples/php5/reference/example.i
new file mode 100644
index 000000000..df1459921
--- /dev/null
+++ b/Examples/php5/reference/example.i
@@ -0,0 +1,43 @@
+/* File : example.i */
+
+/* This file has a few "typical" uses of C++ references. */
+
+%module example
+
+%{
+#include "example.h"
+%}
+
+class Vector {
+public:
+ Vector(double x, double y, double z);
+ ~Vector();
+ char *as_string();
+};
+
+/* This helper function calls an overloaded operator */
+%inline %{
+Vector addv(Vector &a, Vector &b) {
+ return a+b;
+}
+%}
+
+/* Wrapper around an array of vectors class */
+
+class VectorArray {
+public:
+ VectorArray(int maxsize);
+ ~VectorArray();
+ int size();
+
+ /* This wrapper provides an alternative to the [] operator */
+ %extend {
+ Vector &get(int index) {
+ printf("VectorArray extended get: %p %d\n", (void *)$self, index);
+ return (*$self)[index];
+ }
+ void set(int index, Vector &a) {
+ (*$self)[index] = a;
+ }
+ }
+};
diff --git a/Examples/php5/reference/runme.php b/Examples/php5/reference/runme.php
new file mode 100644
index 000000000..5d264ee43
--- /dev/null
+++ b/Examples/php5/reference/runme.php
@@ -0,0 +1,49 @@
+as_string()}\n";
+print " Created b: {$b->as_string()}\n";
+
+# ----- Call an overloaded operator -----
+
+# This calls the wrapper we placed around
+#
+# operator+(const Vector &a, const Vector &)
+#
+# It returns a new allocated object.
+
+print "Adding a+b\n";
+$c = example::addv($a, $b);
+print " a+b ={$c->as_string()}\n";
+
+# ----- Create a vector array -----
+
+print "Creating an array of vectors\n";
+$va = new VectorArray(10);
+
+print " va: size={$va->size()}\n";
+
+# ----- Set some values in the array -----
+
+# These operators copy the value of $a and $b to the vector array
+$va->set(0, $a);
+$va->set(1, $b);
+$va->set(2, addv($a, $b));
+
+# Get some values from the array
+
+print "Getting some array values\n";
+for ($i = 0; $i < 5; $i++) {
+ print " va[$i] = {$va->get($i)->as_string()}\n";
+}
+
+?>
diff --git a/Examples/php5/simple/Makefile b/Examples/php5/simple/Makefile
new file mode 100644
index 000000000..47e5ed9f9
--- /dev/null
+++ b/Examples/php5/simple/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/simple/example.c b/Examples/php5/simple/example.c
new file mode 100644
index 000000000..2fe275632
--- /dev/null
+++ b/Examples/php5/simple/example.c
@@ -0,0 +1,23 @@
+/* File : example.c */
+#include
+
+/* A global variable */
+double Foo = 3.0;
+
+void print_Foo() {
+ printf("In C, Foo = %f\n",Foo);
+}
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/php5/simple/example.i b/Examples/php5/simple/example.i
new file mode 100644
index 000000000..9d4e22aa9
--- /dev/null
+++ b/Examples/php5/simple/example.i
@@ -0,0 +1,8 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+void print_Foo();
+%}
diff --git a/Examples/php5/simple/runme.php b/Examples/php5/simple/runme.php
new file mode 100644
index 000000000..0e96fe800
--- /dev/null
+++ b/Examples/php5/simple/runme.php
@@ -0,0 +1,25 @@
+
diff --git a/Examples/php5/sync/Makefile b/Examples/php5/sync/Makefile
new file mode 100644
index 000000000..063a0645f
--- /dev/null
+++ b/Examples/php5/sync/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+CXXSRCS = example.cxx
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php_cpp
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/sync/example.cxx b/Examples/php5/sync/example.cxx
new file mode 100644
index 000000000..0942279b2
--- /dev/null
+++ b/Examples/php5/sync/example.cxx
@@ -0,0 +1,13 @@
+#include "example.h"
+#include
+
+int x = 42;
+char *s = (char *)"Test";
+
+void Sync::printer(void) {
+
+ printf("The value of global s is %s\n", s);
+ printf("The value of global x is %d\n", x);
+ printf("The value of class s is %s\n", s);
+ printf("The value of class x is %d\n", x);
+}
diff --git a/Examples/php5/sync/example.h b/Examples/php5/sync/example.h
new file mode 100644
index 000000000..d67ec21dc
--- /dev/null
+++ b/Examples/php5/sync/example.h
@@ -0,0 +1,9 @@
+extern char *s;
+extern int x;
+
+class Sync {
+ public:
+ int x;
+ char *s;
+ void printer(void);
+};
diff --git a/Examples/php5/sync/example.i b/Examples/php5/sync/example.i
new file mode 100644
index 000000000..17ff87cf3
--- /dev/null
+++ b/Examples/php5/sync/example.i
@@ -0,0 +1,7 @@
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include "example.h"
diff --git a/Examples/php5/sync/runme.php b/Examples/php5/sync/runme.php
new file mode 100644
index 000000000..a7c43474f
--- /dev/null
+++ b/Examples/php5/sync/runme.php
@@ -0,0 +1,15 @@
+
+
+// Load module and PHP classes.
+include("example.php");
+
+echo "Got new object\n";
+echo "Got string $s and value $x \n";
+
+$s = new Sync();
+echo "Got new object\n";
+
+$s->printer();
+
+?>
+
diff --git a/Examples/php5/value/Makefile b/Examples/php5/value/Makefile
new file mode 100644
index 000000000..28fc3a127
--- /dev/null
+++ b/Examples/php5/value/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT = -noproxy
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/value/example.c b/Examples/php5/value/example.c
new file mode 100644
index 000000000..3c402a214
--- /dev/null
+++ b/Examples/php5/value/example.c
@@ -0,0 +1,13 @@
+/* File : example.c */
+
+#include "example.h"
+
+double dot_product(Vector a, Vector b) {
+ return (a.x*b.x + a.y*b.y + a.z*b.z);
+}
+
+void vector_add(Vector a, Vector b, Vector* result) {
+ result->x = a.x + b.x;
+ result->y = a.y + b.y;
+ result->z = a.z + b.z;
+}
diff --git a/Examples/php5/value/example.h b/Examples/php5/value/example.h
new file mode 100644
index 000000000..f55752a5f
--- /dev/null
+++ b/Examples/php5/value/example.h
@@ -0,0 +1,8 @@
+/* File : example.h */
+
+typedef struct {
+ double x, y, z;
+} Vector;
+
+double dot_product(Vector a, Vector b);
+void vector_add(Vector a, Vector b, Vector* result);
diff --git a/Examples/php5/value/example.i b/Examples/php5/value/example.i
new file mode 100644
index 000000000..20a453468
--- /dev/null
+++ b/Examples/php5/value/example.i
@@ -0,0 +1,17 @@
+// Tests SWIG's handling of pass-by-value for complex datatypes
+%module example
+
+%{
+#include "example.h"
+%}
+
+%include "example.h"
+
+/* Some helper functions for our interface */
+%inline %{
+
+void vector_print(Vector *v) {
+ printf("Vector %p = (%g, %g, %g)\n", (void *)v, v->x, v->y, v->z);
+}
+%}
+
diff --git a/Examples/php5/value/runme.php b/Examples/php5/value/runme.php
new file mode 100644
index 000000000..49115376c
--- /dev/null
+++ b/Examples/php5/value/runme.php
@@ -0,0 +1,43 @@
+
+
+
diff --git a/Examples/php5/variables/Makefile b/Examples/php5/variables/Makefile
new file mode 100644
index 000000000..47e5ed9f9
--- /dev/null
+++ b/Examples/php5/variables/Makefile
@@ -0,0 +1,20 @@
+TOP = ../..
+SWIGEXE = $(TOP)/../swig
+SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+LIBS =
+SWIGOPT =
+
+check: build
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_run
+
+build:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
+ SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
+ php
+
+clean:
+ $(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
diff --git a/Examples/php5/variables/example.c b/Examples/php5/variables/example.c
new file mode 100644
index 000000000..d4c6d026d
--- /dev/null
+++ b/Examples/php5/variables/example.c
@@ -0,0 +1,95 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include
+#include
+#include "example.h"
+
+int ivar = 0;
+short svar = 0;
+long lvar = 0;
+unsigned int uivar = 0;
+unsigned short usvar = 0;
+unsigned long ulvar = 0;
+signed char scvar = 0;
+unsigned char ucvar = 0;
+char cvar = 0;
+float fvar = 0;
+double dvar = 0;
+char *strvar = 0;
+const char cstrvar[] = "Goodbye";
+int *iptrvar = 0;
+char name[5] = "Dave";
+char path[256] = "/home/beazley";
+
+
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
+/* A debugging function to print out their values */
+
+void print_vars() {
+ printf("ivar = %d\n", ivar);
+ printf("svar = %d\n", svar);
+ printf("lvar = %ld\n", lvar);
+ printf("uivar = %u\n", uivar);
+ printf("usvar = %u\n", usvar);
+ printf("ulvar = %lu\n", ulvar);
+ printf("scvar = %d\n", scvar);
+ printf("ucvar = %u\n", ucvar);
+ printf("fvar = %g\n", fvar);
+ printf("dvar = %g\n", dvar);
+ printf("cvar = %c\n", cvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar);
+ printf("iptrvar = %p\n", (void *)iptrvar);
+ printf("name = %c%c%c%c%c\n", name[0],name[1],name[2],name[3],name[4]);
+ printf("ptptr = %p %s\n", (void *)ptptr, Point_print( ptptr ) );
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
+}
+
+int value_int(int *value) {
+ return *value;
+}
+
+/* A function to create a point */
+
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d,%d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/php5/variables/example.h b/Examples/php5/variables/example.h
new file mode 100644
index 000000000..3b3659ce5
--- /dev/null
+++ b/Examples/php5/variables/example.h
@@ -0,0 +1,34 @@
+/* File: example.h */
+
+typedef struct {
+ int x,y;
+} Point;
+
+/* Some global variable declarations */
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[5];
+
+extern Point *ptptr;
+extern Point pt;
+
+extern int status;
+extern char path[256];
+
+extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
diff --git a/Examples/php5/variables/example.i b/Examples/php5/variables/example.i
new file mode 100644
index 000000000..3edbb72d7
--- /dev/null
+++ b/Examples/php5/variables/example.i
@@ -0,0 +1,44 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Some global variable declarations */
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[5];
+
+extern Point *ptptr;
+extern Point pt;
+
+/* Some read-only variables */
+
+%immutable;
+extern int status;
+extern char path[256];
+%mutable;
+
+/* Some helper functions to make it easier to test */
+extern void print_vars();
+extern int *new_int(int value);
+
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
+
+
+
+
diff --git a/Examples/php5/variables/runme.php b/Examples/php5/variables/runme.php
new file mode 100644
index 000000000..bbfeb610b
--- /dev/null
+++ b/Examples/php5/variables/runme.php
@@ -0,0 +1,96 @@
+
+
diff --git a/Examples/test-suite/php/director_thread_runme.php b/Examples/test-suite/php/director_thread_runme.php
index 809dec3e2..ab0563213 100644
--- a/Examples/test-suite/php/director_thread_runme.php
+++ b/Examples/test-suite/php/director_thread_runme.php
@@ -3,7 +3,8 @@
require "tests.php";
require "director_thread.php";
-# Fails in a ZTS-build of PHP - see: https://github.com/swig/swig/pull/155
+# Fails in a ZTS-build of PHP5 - see: https://github.com/swig/swig/pull/155
+# FIXME: Does this still fail in a threaded build of PHP7?
exit(0);
// No new functions
diff --git a/Examples/test-suite/php5/Makefile.in b/Examples/test-suite/php5/Makefile.in
new file mode 100644
index 000000000..307fecea3
--- /dev/null
+++ b/Examples/test-suite/php5/Makefile.in
@@ -0,0 +1,79 @@
+#######################################################################
+# Makefile for php5 test-suite
+#######################################################################
+
+LANGUAGE = php5
+SCRIPTSUFFIX = _runme.php
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+
+CPP_TEST_CASES += \
+ callback \
+ php_iterator \
+ php_namewarn_rename \
+
+include $(srcdir)/../common.mk
+
+# Overridden variables here
+TARGETPREFIX =# Should be php_ for Windows, empty otherwise
+
+# Custom tests - tests with additional commandline options
+prefix.cpptest: SWIGOPT += -prefix Project
+
+# write out tests without a _runme.php
+missingcpptests:
+ for test in $(CPP_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done
+
+missingctests:
+ for test in $(C_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done
+
+missingtests: missingcpptests missingctests
+
+# Rules for the different types of tests
+%.cpptest:
+ $(setup)
+ +$(swig_and_compile_cpp)
+ +$(run_testcase)
+
+%.ctest:
+ $(setup)
+ +$(swig_and_compile_c)
+ +$(run_testcase)
+
+%.multicpptest:
+ $(setup)
+ +$(swig_and_compile_multi_cpp)
+ +$(run_testcase)
+
+# Smart target
+%.test:
+ @echo ' $(C_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\
+ $(MAKE) $*.ctest
+ @echo ' $(CPP_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\
+ $(MAKE) $*.cpptest
+ @echo ' $(MULTI_CPP_TEST_CASES) '|grep -F -v ' $* ' >/dev/null ||\
+ $(MAKE) $*.multicpptest
+
+# Runs the testcase. Tries to run testcase_runme.php, and if that's not
+# found, runs testcase.php, except for multicpptests.
+run_testcase = \
+ if [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) ]; then \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP5_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) RUNTOOL='$(RUNTOOL)' php5_run; \
+ elif [ -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php -a ! -f $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list ]; then \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile PHP5_SCRIPT=$(SCRIPTDIR)/$(SCRIPTPREFIX)$*.php RUNTOOL='$(RUNTOOL)' php5_run; \
+ fi
+
+# Clean: remove the generated .php file
+%.clean:
+ @rm -f $*.php php_$*.h
+
+clean:
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR='$(SRCDIR)' php5_clean
+ rm -f clientdata_prop_a.php clientdata_prop_b.php php_clientdata_prop_a.h php_clientdata_prop_b.h
+ rm -f import_stl_a.php import_stl_b.php php_import_stl_a.h php_import_stl_b.h
+ rm -f imports_a.php imports_b.php php_imports_a.h php_imports_b.h
+ rm -f mod_a.php mod_b.php php_mod_a.h php_mod_b.h
+ rm -f multi_import_a.php multi_import_b.php php_multi_import_a.h php_multi_import_b.h
+ rm -f packageoption_a.php packageoption_b.php packageoption_c.php php_packageoption_a.h php_packageoption_b.h php_packageoption_c.h
diff --git a/Examples/test-suite/php5/abstract_inherit_ok_runme.php b/Examples/test-suite/php5/abstract_inherit_ok_runme.php
new file mode 100644
index 000000000..c2d86499b
--- /dev/null
+++ b/Examples/test-suite/php5/abstract_inherit_ok_runme.php
@@ -0,0 +1,12 @@
+blah(),"spam object method");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/abstract_inherit_runme.php b/Examples/test-suite/php5/abstract_inherit_runme.php
new file mode 100644
index 000000000..3554e6fd8
--- /dev/null
+++ b/Examples/test-suite/php5/abstract_inherit_runme.php
@@ -0,0 +1,14 @@
+blah(),"spam object method");
+//check::equal(0,Spam::blah($spam),"spam class method");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/add_link_runme.php b/Examples/test-suite/php5/add_link_runme.php
new file mode 100644
index 000000000..7523bd604
--- /dev/null
+++ b/Examples/test-suite/php5/add_link_runme.php
@@ -0,0 +1,22 @@
+blah();
+check::is_a($foo_blah,foo);
+
+//fails, can't be called as a class method, should allow and make it nil?
+//$class_foo_blah=foo::blah();
+//check::is_a($class_foo_blah,foo);
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/argout_runme.php b/Examples/test-suite/php5/argout_runme.php
new file mode 100644
index 000000000..33fbd8129
--- /dev/null
+++ b/Examples/test-suite/php5/argout_runme.php
@@ -0,0 +1,38 @@
+
diff --git a/Examples/test-suite/php5/arrayptr_runme.php b/Examples/test-suite/php5/arrayptr_runme.php
new file mode 100644
index 000000000..3b9baed05
--- /dev/null
+++ b/Examples/test-suite/php5/arrayptr_runme.php
@@ -0,0 +1,14 @@
+
diff --git a/Examples/test-suite/php5/arrays_global_runme.php b/Examples/test-suite/php5/arrays_global_runme.php
new file mode 100644
index 000000000..12a7806c9
--- /dev/null
+++ b/Examples/test-suite/php5/arrays_global_runme.php
@@ -0,0 +1,19 @@
+
diff --git a/Examples/test-suite/php5/arrays_global_twodim_runme.php b/Examples/test-suite/php5/arrays_global_twodim_runme.php
new file mode 100644
index 000000000..40ecf1719
--- /dev/null
+++ b/Examples/test-suite/php5/arrays_global_twodim_runme.php
@@ -0,0 +1,22 @@
+
diff --git a/Examples/test-suite/php5/arrays_runme.php b/Examples/test-suite/php5/arrays_runme.php
new file mode 100644
index 000000000..ae17d05e7
--- /dev/null
+++ b/Examples/test-suite/php5/arrays_runme.php
@@ -0,0 +1,18 @@
+array_c="abc";
+check::equal($as->array_c,"a",'$as->array_c=="a"');
+check::equal(isset($as->array_const_i),TRUE,'isset($as->array_const_i)');
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/arrays_scope_runme.php b/Examples/test-suite/php5/arrays_scope_runme.php
new file mode 100644
index 000000000..c208b7518
--- /dev/null
+++ b/Examples/test-suite/php5/arrays_scope_runme.php
@@ -0,0 +1,16 @@
+
diff --git a/Examples/test-suite/php5/callback_runme.php b/Examples/test-suite/php5/callback_runme.php
new file mode 100644
index 000000000..fefa32502
--- /dev/null
+++ b/Examples/test-suite/php5/callback_runme.php
@@ -0,0 +1,9 @@
+
diff --git a/Examples/test-suite/php5/casts_runme.php b/Examples/test-suite/php5/casts_runme.php
new file mode 100644
index 000000000..10522dca4
--- /dev/null
+++ b/Examples/test-suite/php5/casts_runme.php
@@ -0,0 +1,18 @@
+hello();
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/char_strings_runme.php b/Examples/test-suite/php5/char_strings_runme.php
new file mode 100644
index 000000000..e06ee9d2b
--- /dev/null
+++ b/Examples/test-suite/php5/char_strings_runme.php
@@ -0,0 +1,43 @@
+
diff --git a/Examples/test-suite/php5/class_ignore_runme.php b/Examples/test-suite/php5/class_ignore_runme.php
new file mode 100644
index 000000000..d5ce36217
--- /dev/null
+++ b/Examples/test-suite/php5/class_ignore_runme.php
@@ -0,0 +1,16 @@
+
diff --git a/Examples/test-suite/php5/conversion_namespace_runme.php b/Examples/test-suite/php5/conversion_namespace_runme.php
new file mode 100644
index 000000000..e21ff7438
--- /dev/null
+++ b/Examples/test-suite/php5/conversion_namespace_runme.php
@@ -0,0 +1,13 @@
+toFoo();
+check::classname("foo",$foo);
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/conversion_ns_template_runme.php b/Examples/test-suite/php5/conversion_ns_template_runme.php
new file mode 100644
index 000000000..9702eedb7
--- /dev/null
+++ b/Examples/test-suite/php5/conversion_ns_template_runme.php
@@ -0,0 +1,10 @@
+
diff --git a/Examples/test-suite/php5/conversion_runme.php b/Examples/test-suite/php5/conversion_runme.php
new file mode 100644
index 000000000..1a10ff4f4
--- /dev/null
+++ b/Examples/test-suite/php5/conversion_runme.php
@@ -0,0 +1,13 @@
+toFoo();
+check::classname("foo",$foo);
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/cpp11_strongly_typed_enumerations_runme.php b/Examples/test-suite/php5/cpp11_strongly_typed_enumerations_runme.php
new file mode 100644
index 000000000..bee59b209
--- /dev/null
+++ b/Examples/test-suite/php5/cpp11_strongly_typed_enumerations_runme.php
@@ -0,0 +1,169 @@
+class1Test1(Enum1_Val5a), 13);
+enumCheck($class1->class1Test2(Class1::Enum12_Val5c), 1121);
+#enumCheck($class1.class1Test3(Class1::Struct1.Enum12_Val5f), 3121);
+
+enumCheck(globalTest1(Enum1_Val5a), 13);
+enumCheck(globalTest2(Class1::Enum12_Val5c), 1121);
+#enumCheck(globalTest3(Class1::Struct1.Enum12_Val5f), 3121);
+
+?>
diff --git a/Examples/test-suite/php5/cpp_basic_runme.php b/Examples/test-suite/php5/cpp_basic_runme.php
new file mode 100644
index 000000000..6a8522e3e
--- /dev/null
+++ b/Examples/test-suite/php5/cpp_basic_runme.php
@@ -0,0 +1,20 @@
+func_ptr = get_func1_ptr();
+check::equal(test_func_ptr($f, 7), 2*7*3, "get_func1_ptr() didn't work");
+$f->func_ptr = get_func2_ptr();
+check::equal(test_func_ptr($f, 7), -7*3, "get_func2_ptr() didn't work");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/cpp_static_runme.php b/Examples/test-suite/php5/cpp_static_runme.php
new file mode 100644
index 000000000..9b436b87c
--- /dev/null
+++ b/Examples/test-suite/php5/cpp_static_runme.php
@@ -0,0 +1,14 @@
+
diff --git a/Examples/test-suite/php5/director_abstract_runme.php b/Examples/test-suite/php5/director_abstract_runme.php
new file mode 100644
index 000000000..ca3d676da
--- /dev/null
+++ b/Examples/test-suite/php5/director_abstract_runme.php
@@ -0,0 +1,62 @@
+ping(), "MyFoo::ping()", "MyFoo::ping failed");
+
+check::equal($a->pong(), "Foo::pong();MyFoo::ping()", "MyFoo::pong failed");
+
+class MyExample1 extends Example1 {
+ function Color($r, $g, $b) {
+ return $r;
+ }
+}
+
+class MyExample2 extends Example1 {
+ function Color($r, $g, $b) {
+ return $g;
+ }
+}
+
+class MyExample3 extends Example1 {
+ function Color($r, $g, $b) {
+ return $b;
+ }
+}
+
+$me1 = new MyExample1();
+check::equal($me1->Color(1, 2, 3), 1, "Example1_get_color failed");
+
+$me2 = new MyExample2(1, 2);
+check::equal($me2->Color(1, 2, 3), 2, "Example2_get_color failed");
+
+$me3 = new MyExample3();
+check::equal($me3->Color(1, 2, 3), 3, "Example3_get_color failed");
+
+$class = new ReflectionClass('Example1');
+check::equal($class->isAbstract(), true, "Example1 abstractness failed");
+
+$class = new ReflectionClass('Example2');
+check::equal($class->isAbstract(), true, "Example2 abstractness failed");
+
+$class = new ReflectionClass('Example3_i');
+check::equal($class->isAbstract(), true, "Example3_i abstractness failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_basic_runme.php b/Examples/test-suite/php5/director_basic_runme.php
new file mode 100644
index 000000000..de6b50502
--- /dev/null
+++ b/Examples/test-suite/php5/director_basic_runme.php
@@ -0,0 +1,58 @@
+ping(), "PhpFoo::ping()", "ping failed");
+
+check::equal($a->pong(), "Foo::pong();PhpFoo::ping()", "pong failed");
+
+$b = new Foo();
+
+check::equal($b->ping(), "Foo::ping()", "ping failed");
+
+check::equal($b->pong(), "Foo::pong();Foo::ping()", "pong failed");
+
+$a = new A1(1);
+
+check::equal($a->rg(2), 2, "rg failed");
+
+class PhpClass extends MyClass {
+ function vmethod($b) {
+ $b->x = $b->x + 31;
+ return $b;
+ }
+}
+
+$b = new Bar(3);
+$d = new MyClass();
+$c = new PhpClass();
+
+$cc = MyClass::get_self($c);
+$dd = MyClass::get_self($d);
+
+$bc = $cc->cmethod($b);
+$bd = $dd->cmethod($b);
+
+$cc->method($b);
+
+check::equal($bc->x, 34, "bc failed");
+check::equal($bd->x, 16, "bd failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_classic_runme.php b/Examples/test-suite/php5/director_classic_runme.php
new file mode 100644
index 000000000..d2da1b1ba
--- /dev/null
+++ b/Examples/test-suite/php5/director_classic_runme.php
@@ -0,0 +1,150 @@
+id();
+ if ($debug)
+ print $ret . "\n";
+ check::equal($ret, $expected, "#1 failed");
+
+ # Polymorphic call from C++
+ $caller = new Caller();
+ $caller->setCallback($person);
+ $ret = $caller->call();
+ if ($debug)
+ print $ret . "\n";
+ check::equal($ret, $expected, "#2 failed");
+
+ # Polymorphic call of object created in target language and passed to
+ # C++ and back again
+ $baseclass = $caller->baseClass();
+ $ret = $baseclass->id();
+ if ($debug)
+ print $ret . "\n";
+ # TODO: Currently we do not track the dynamic type of returned
+ # objects, so in case it's possible that the dynamic type is not equal
+ # to the static type, we skip this check.
+ if (get_parent_class($person) === false)
+ check::equal($ret, $expected, "#3 failed");
+
+ $caller->resetCallback();
+ if ($debug)
+ print "----------------------------------------\n";
+}
+
+$person = new Person();
+mycheck($person, "Person");
+unset($person);
+
+$person = new Child();
+mycheck($person, "Child");
+unset($person);
+
+$person = new GrandChild();
+mycheck($person, "GrandChild");
+unset($person);
+
+$person = new TargetLangPerson();
+mycheck($person, "TargetLangPerson");
+unset($person);
+
+$person = new TargetLangChild();
+mycheck($person, "TargetLangChild");
+unset($person);
+
+$person = new TargetLangGrandChild();
+mycheck($person, "TargetLangGrandChild");
+unset($person);
+
+# Semis - don't override id() in target language
+$person = new TargetLangSemiPerson();
+mycheck($person, "Person");
+unset($person);
+
+$person = new TargetLangSemiChild();
+mycheck($person, "Child");
+unset($person);
+
+$person = new TargetLangSemiGrandChild();
+mycheck($person, "GrandChild");
+unset($person);
+
+# Orphans - don't override id() in C++
+$person = new OrphanPerson();
+mycheck($person, "Person");
+unset($person);
+
+$person = new OrphanChild();
+mycheck($person, "Child");
+unset($person);
+
+$person = new TargetLangOrphanPerson();
+mycheck($person, "TargetLangOrphanPerson");
+unset($person);
+
+$person = new TargetLangOrphanChild();
+mycheck($person, "TargetLangOrphanChild");
+unset($person);
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_default_runme.php b/Examples/test-suite/php5/director_default_runme.php
new file mode 100644
index 000000000..f97fc7425
--- /dev/null
+++ b/Examples/test-suite/php5/director_default_runme.php
@@ -0,0 +1,20 @@
+
diff --git a/Examples/test-suite/php5/director_detect_runme.php b/Examples/test-suite/php5/director_detect_runme.php
new file mode 100644
index 000000000..cc19c0302
--- /dev/null
+++ b/Examples/test-suite/php5/director_detect_runme.php
@@ -0,0 +1,55 @@
+val = $val;
+ }
+
+ function get_value() {
+ $this->val = $this->val + 1;
+ return $this->val;
+ }
+
+ function get_class() {
+ $this->val = $this->val + 1;
+ return new A();
+ }
+
+ function just_do_it() {
+ $this->val = $this->val + 1;
+ }
+
+ /* clone is a reserved keyword */
+ function clone_() {
+ return new MyBar($this->val);
+ }
+}
+
+$b = new MyBar();
+
+$f = $b->baseclass();
+
+$v = $f->get_value();
+$a = $f->get_class();
+$f->just_do_it();
+
+$c = $b->clone_();
+$vc = $c->get_value();
+
+check::equal($v, 3, "f: Bad virtual detection");
+check::equal($b->val, 5, "b: Bad virtual detection");
+check::equal($vc, 6, "c: Bad virtual detection");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_enum_runme.php b/Examples/test-suite/php5/director_enum_runme.php
new file mode 100644
index 000000000..8f6487a28
--- /dev/null
+++ b/Examples/test-suite/php5/director_enum_runme.php
@@ -0,0 +1,25 @@
+say_hi(director_enum::hello), $b->say_hello(director_enum::hi), "say failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_exception_runme.php b/Examples/test-suite/php5/director_exception_runme.php
new file mode 100644
index 000000000..8b852c2ce
--- /dev/null
+++ b/Examples/test-suite/php5/director_exception_runme.php
@@ -0,0 +1,127 @@
+msg = $a . $b;
+ }
+}
+
+class MyFoo extends Foo {
+ function ping() {
+ throw new Exception("MyFoo::ping() EXCEPTION");
+ }
+}
+
+class MyFoo2 extends Foo {
+ function ping() {
+ return true;
+ }
+}
+
+class MyFoo3 extends Foo {
+ function ping() {
+ throw new MyException("foo", "bar");
+ }
+}
+
+# Check that the Exception raised by MyFoo.ping() is returned by
+# MyFoo.pong().
+$ok = 0;
+$a = new MyFoo();
+# TODO: Currently we do not track the dynamic type of returned
+# objects, so we skip the launder() call.
+#$b = director_exception::launder($a);
+$b = $a;
+try {
+ $b->pong();
+} catch (Exception $e) {
+ $ok = 1;
+ check::equal($e->getMessage(), "MyFoo::ping() EXCEPTION", "Unexpected error message #1");
+}
+check::equal($ok, 1, "Got no exception while expected one #1");
+
+# Check that the director can return an exception which requires two
+# arguments to the constructor, without mangling it.
+$ok = 0;
+$a = new MyFoo3();
+#$b = director_exception::launder($a);
+$b = $a;
+try {
+ $b->pong();
+} catch (Exception $e) {
+ $ok = 1;
+ check::equal($e->msg, "foobar", "Unexpected error message #2");
+}
+check::equal($ok, 1, "Got no exception while expected one #2");
+
+try {
+ throw new Exception2();
+} catch (Exception2 $e2) {
+}
+
+try {
+ throw new Exception1();
+} catch (Exception1 $e1) {
+}
+
+// Check that we can throw exceptions from director methods (this didn't used
+// to work in all cases, as the exception gets "set" in PHP and the method
+// then returns PHP NULL, which the directorout template may fail to convert.
+
+class Bad extends ReturnAllTypes {
+ function return_int() { throw new Exception("bad int"); }
+ function return_double() { throw new Exception("bad double"); }
+ function return_const_char_star() { throw new Exception("bad const_char_star"); }
+ function return_std_string() { throw new Exception("bad std_string"); }
+ function return_Bar() { throw new Exception("bad Bar"); }
+}
+
+$bad = new Bad();
+
+try {
+ $bad->call_int();
+ check::fail("Exception wasn't propagated from Bad::return_int()");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "bad int", "propagated exception incorrect");
+}
+
+try {
+ $bad->call_double();
+ check::fail("Exception wasn't propagated from Bad::return_double()");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "bad double", "propagated exception incorrect");
+}
+
+try {
+ $bad->call_const_char_star();
+ check::fail("Exception wasn't propagated from Bad::return_const_char_star()");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "bad const_char_star", "propagated exception incorrect");
+}
+
+try {
+ $bad->call_std_string();
+ check::fail("Exception wasn't propagated from Bad::return_std_string()");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "bad std_string", "propagated exception incorrect");
+}
+
+try {
+ $bad->call_Bar();
+ check::fail("Exception wasn't propagated from Bad::return_Bar()");
+} catch (Exception $e) {
+ check::equal($e->getMessage(), "bad Bar", "propagated exception incorrect");
+}
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_extend_runme.php b/Examples/test-suite/php5/director_extend_runme.php
new file mode 100644
index 000000000..f283aefbe
--- /dev/null
+++ b/Examples/test-suite/php5/director_extend_runme.php
@@ -0,0 +1,24 @@
+dummy(), 666, "1st call");
+check::equal($m->dummy(), 666, "2st call"); // Locked system
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_finalizer_runme.php b/Examples/test-suite/php5/director_finalizer_runme.php
new file mode 100644
index 000000000..0fcddfd8b
--- /dev/null
+++ b/Examples/test-suite/php5/director_finalizer_runme.php
@@ -0,0 +1,61 @@
+orStatus(2);
+ if (method_exists(parent, "__destruct")) {
+ parent::__destruct();
+ }
+ }
+}
+
+resetStatus();
+
+$a = new MyFoo();
+unset($a);
+
+check::equal(getStatus(), 3, "getStatus() failed #1");
+
+resetStatus();
+
+$a = new MyFoo();
+launder($a);
+
+check::equal(getStatus(), 0, "getStatus() failed #2");
+
+unset($a);
+
+check::equal(getStatus(), 3, "getStatus() failed #3");
+
+resetStatus();
+
+$a = new MyFoo();
+$a->thisown = 0;
+deleteFoo($a);
+unset($a);
+
+check::equal(getStatus(), 3, "getStatus() failed #4");
+
+resetStatus();
+
+$a = new MyFoo();
+$a->thisown = 0;
+deleteFoo(launder($a));
+unset($a);
+
+check::equal(getStatus(), 3, "getStatus() failed #5");
+
+resetStatus();
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_frob_runme.php b/Examples/test-suite/php5/director_frob_runme.php
new file mode 100644
index 000000000..548b0b804
--- /dev/null
+++ b/Examples/test-suite/php5/director_frob_runme.php
@@ -0,0 +1,19 @@
+abs_method();
+
+check::equal($s, "Bravo::abs_method()", "s failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_nested_runme.php b/Examples/test-suite/php5/director_nested_runme.php
new file mode 100644
index 000000000..4965e94f7
--- /dev/null
+++ b/Examples/test-suite/php5/director_nested_runme.php
@@ -0,0 +1,74 @@
+step(), "Bar::step;Foo::advance;Bar::do_advance;A::do_step;", "Bad A virtual resolution");
+
+class B extends FooBar_int {
+ function do_advance() {
+ return "B::do_advance;" . $this->do_step();
+ }
+
+ function do_step() {
+ return "B::do_step;";
+ }
+
+ function get_value() {
+ return 1;
+ }
+}
+
+$b = new B();
+
+check::equal($b->step(), "Bar::step;Foo::advance;B::do_advance;B::do_step;", "Bad B virtual resolution");
+
+class C extends FooBar_int {
+ function do_advance() {
+ return "C::do_advance;" . parent::do_advance();
+ }
+
+ function do_step() {
+ return "C::do_step;";
+ }
+
+ function get_value() {
+ return 2;
+ }
+
+ function get_name() {
+ return parent::get_name() . " hello";
+ }
+}
+
+$cc = new C();
+# TODO: Currently we do not track the dynamic type of returned
+# objects, so we skip the get_self() call.
+#$c = Foobar_int::get_self($cc);
+$c = $cc;
+$c->advance();
+
+check::equal($c->get_name(), "FooBar::get_name hello", "get_name failed");
+
+check::equal($c->name(), "FooBar::get_name hello", "name failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_pass_by_value_runme.php b/Examples/test-suite/php5/director_pass_by_value_runme.php
new file mode 100644
index 000000000..8a8b84d67
--- /dev/null
+++ b/Examples/test-suite/php5/director_pass_by_value_runme.php
@@ -0,0 +1,24 @@
+call_virtualMethod(new director_pass_by_value_Derived());
+$ret = $passByVal->getVal();
+if ($ret != 0x12345678) {
+ check::fail("Bad return value, got " . dechex($ret));
+}
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_profile_runme.php b/Examples/test-suite/php5/director_profile_runme.php
new file mode 100644
index 000000000..c72421341
--- /dev/null
+++ b/Examples/test-suite/php5/director_profile_runme.php
@@ -0,0 +1,53 @@
+fi($a); #1
+ $a = $b->fi($a); #2
+ $a = $b->fi($a); #3
+ $a = $b->fi($a); #4
+ $a = $b->fi($a); #5
+ $a = $b->fi($a); #6
+ $a = $b->fi($a); #7
+ $a = $b->fi($a); #8
+ $a = $b->fi($a); #9
+ $a = $b->fi($a); #10
+ $a = $b->fi($a); #1
+ $a = $b->fi($a); #2
+ $a = $b->fi($a); #3
+ $a = $b->fi($a); #4
+ $a = $b->fi($a); #5
+ $a = $b->fi($a); #6
+ $a = $b->fi($a); #7
+ $a = $b->fi($a); #8
+ $a = $b->fi($a); #9
+ $a = $b->fi($a); #20
+ $i -= 1;
+}
+
+print $a . "\n";
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_protected_runme.php b/Examples/test-suite/php5/director_protected_runme.php
new file mode 100644
index 000000000..18586ca62
--- /dev/null
+++ b/Examples/test-suite/php5/director_protected_runme.php
@@ -0,0 +1,70 @@
+create();
+$fb = new FooBar();
+$fb2 = new FooBar2();
+$fb3 = new FooBar3();
+
+check::equal($fb->used(), "Foo::pang();Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::used");
+
+check::equal($fb2->used(), "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();", "bad FooBar2::used");
+
+check::equal($b->pong(), "Bar::pong();Foo::pong();Bar::ping();", "bad Bar::pong");
+
+check::equal($f->pong(), "Bar::pong();Foo::pong();Bar::ping();", "bad Foo::pong");
+
+check::equal($fb->pong(), "Bar::pong();Foo::pong();FooBar::ping();", "bad FooBar::pong");
+
+$method = new ReflectionMethod('Bar', 'ping');
+check::equal($method->isProtected(), true, "Foo::ping should be protected");
+
+$method = new ReflectionMethod('Foo', 'ping');
+check::equal($method->isProtected(), true, "Foo::ping should be protected");
+
+$method = new ReflectionMethod('FooBar', 'pang');
+check::equal($method->isProtected(), true, "FooBar::pang should be protected");
+
+$method = new ReflectionMethod('Bar', 'cheer');
+check::equal($method->isProtected(), true, "Bar::cheer should be protected");
+
+$method = new ReflectionMethod('Foo', 'cheer');
+check::equal($method->isProtected(), true, "Foo::cheer should be protected");
+
+check::equal($fb3->cheer(), "FooBar3::cheer();", "bad fb3::pong");
+check::equal($fb2->callping(), "FooBar2::ping();", "bad fb2::callping");
+check::equal($fb2->callcheer(), "FooBar2::pang();Bar::pong();Foo::pong();FooBar2::ping();", "bad fb2::callcheer");
+check::equal($fb3->callping(), "Bar::ping();", "bad fb3::callping");
+check::equal($fb3->callcheer(), "FooBar3::cheer();", "bad fb3::callcheer");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_stl_runme.php b/Examples/test-suite/php5/director_stl_runme.php
new file mode 100644
index 000000000..29addd261
--- /dev/null
+++ b/Examples/test-suite/php5/director_stl_runme.php
@@ -0,0 +1,60 @@
+tping("hello");
+$a->tpong("hello");
+
+# TODO: automatic conversion between PHP arrays and std::pair or
+# std::vector is not yet implemented.
+/*$p = array(1, 2);
+$a->pident($p);
+$v = array(3, 4);
+$a->vident($v);
+
+$a->tpident($p);
+$a->tvident($v);
+
+$v1 = array(3, 4);
+$v2 = array(5, 6);
+
+$a->tvsecond($v1, $v2);
+
+$vs = array("hi", "hello");
+$vs;
+$a->tvidents($vs);*/
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_string_runme.php b/Examples/test-suite/php5/director_string_runme.php
new file mode 100644
index 000000000..5ac583f78
--- /dev/null
+++ b/Examples/test-suite/php5/director_string_runme.php
@@ -0,0 +1,34 @@
+smem = "hello";
+ }
+}
+
+$b = new B("hello");
+
+$b->get(0);
+check::equal($b->get_first(),"hello world!", "get_first failed");
+
+$b->call_process_func();
+
+check::equal($b->smem, "hello", "smem failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_thread_runme.php b/Examples/test-suite/php5/director_thread_runme.php
new file mode 100644
index 000000000..809dec3e2
--- /dev/null
+++ b/Examples/test-suite/php5/director_thread_runme.php
@@ -0,0 +1,32 @@
+val = $this->val - 1;
+ }
+}
+
+$d = new Derived();
+$d->run();
+
+if ($d->val >= 0) {
+ check::fail($d->val);
+}
+
+$d->stop();
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/director_unroll_runme.php b/Examples/test-suite/php5/director_unroll_runme.php
new file mode 100644
index 000000000..626b1f07d
--- /dev/null
+++ b/Examples/test-suite/php5/director_unroll_runme.php
@@ -0,0 +1,29 @@
+set($a);
+$c = $b->get();
+
+check::equal($a->this, $c->this, "this failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/enum_scope_template_runme.php b/Examples/test-suite/php5/enum_scope_template_runme.php
new file mode 100644
index 000000000..85ba467b7
--- /dev/null
+++ b/Examples/test-suite/php5/enum_scope_template_runme.php
@@ -0,0 +1,15 @@
+
diff --git a/Examples/test-suite/php5/evil_diamond_ns_runme.php b/Examples/test-suite/php5/evil_diamond_ns_runme.php
new file mode 100644
index 000000000..fcce0f767
--- /dev/null
+++ b/Examples/test-suite/php5/evil_diamond_ns_runme.php
@@ -0,0 +1,18 @@
+
diff --git a/Examples/test-suite/php5/evil_diamond_prop_runme.php b/Examples/test-suite/php5/evil_diamond_prop_runme.php
new file mode 100644
index 000000000..02d9944d6
--- /dev/null
+++ b/Examples/test-suite/php5/evil_diamond_prop_runme.php
@@ -0,0 +1,38 @@
+_foo,"1==foo->_foo");
+
+$bar=new bar();
+check::is_a($bar,"bar");
+check::equal(1,$bar->_foo,"1==bar->_foo");
+check::equal(2,$bar->_bar,"2==bar->_bar");
+
+$baz=new baz();
+check::is_a($baz,"baz");
+check::equal(1,$baz->_foo,"1==baz->_foo");
+check::equal(3,$baz->_baz,"3==baz->_baz");
+
+$spam=new spam();
+check::is_a($spam,"spam");
+check::equal(1,$spam->_foo,"1==spam->_foo");
+check::equal(2,$spam->_bar,"2==spam->_bar");
+// multiple inheritance not supported in PHP
+check::equal(null,$spam->_baz,"null==spam->_baz");
+check::equal(4,$spam->_spam,"4==spam->_spam");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/evil_diamond_runme.php b/Examples/test-suite/php5/evil_diamond_runme.php
new file mode 100644
index 000000000..a587ca359
--- /dev/null
+++ b/Examples/test-suite/php5/evil_diamond_runme.php
@@ -0,0 +1,16 @@
+
diff --git a/Examples/test-suite/php5/exception_order_runme.php b/Examples/test-suite/php5/exception_order_runme.php
new file mode 100644
index 000000000..acb83561a
--- /dev/null
+++ b/Examples/test-suite/php5/exception_order_runme.php
@@ -0,0 +1,39 @@
+
+require "tests.php";
+require "exception_order.php";
+
+check::functions(array(a_foo,a_bar,a_foobar,a_barfoo,is_python_builtin));
+check::classes(array(A,E1,E2,E3,exception_order,ET_i,ET_d));
+check::globals(array(efoovar,foovar,cfoovar,a_sfoovar,a_foovar,a_efoovar));
+
+$a = new A();
+try {
+ $a->foo();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ E1 exception thrown', '');
+}
+
+try {
+ $a->bar();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ E2 exception thrown', '');
+}
+
+try {
+ $a->foobar();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'postcatch unknown', '');
+}
+
+try {
+ $a->barfoo(1);
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ E1 exception thrown', '');
+}
+
+try {
+ $a->barfoo(2);
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ E2 * exception thrown', '');
+}
+?>
diff --git a/Examples/test-suite/php5/extend_template_ns_runme.php b/Examples/test-suite/php5/extend_template_ns_runme.php
new file mode 100644
index 000000000..e6d3e9f73
--- /dev/null
+++ b/Examples/test-suite/php5/extend_template_ns_runme.php
@@ -0,0 +1,12 @@
+test1(2),"test1");
+check::equal(3,$foo->test2(3),"test2");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/extend_template_runme.php b/Examples/test-suite/php5/extend_template_runme.php
new file mode 100644
index 000000000..41bde4458
--- /dev/null
+++ b/Examples/test-suite/php5/extend_template_runme.php
@@ -0,0 +1,12 @@
+test1(2),"test1");
+check::equal(3,$foo->test2(3),"test2");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/grouping_runme.php b/Examples/test-suite/php5/grouping_runme.php
new file mode 100644
index 000000000..51446f473
--- /dev/null
+++ b/Examples/test-suite/php5/grouping_runme.php
@@ -0,0 +1,22 @@
+
diff --git a/Examples/test-suite/php5/ignore_parameter_runme.php b/Examples/test-suite/php5/ignore_parameter_runme.php
new file mode 100644
index 000000000..1c8c76ad4
--- /dev/null
+++ b/Examples/test-suite/php5/ignore_parameter_runme.php
@@ -0,0 +1,38 @@
+daimler(2,3.4),"hello",'$sc->daimler(2,3.4)=="hello"');
+check::equal($sc->astonmartin("eek",3.4),101,'$sc->mastonmartin("eek",3.4)==101');
+check::equal($sc->bugatti("eek",2),8.8,'$sc->bugatti("eek",2)==8.8');
+check::equal($sc->lamborghini(),101,'$sc->lamborghini(2)==101');
+
+$mc=new minicooper(2,3.4);
+check::classname("minicooper",$mc);
+
+$mm=new morrisminor("eek",3.4);
+check::classname("morrisminor",$mm);
+
+$fa=new fordanglia("eek",2);
+check::classname("fordanglia",$fa);
+
+$aa=new austinallegro();
+check::classname("austinallegro",$aa);
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/import_nomodule_runme.php b/Examples/test-suite/php5/import_nomodule_runme.php
new file mode 100644
index 000000000..41836ba0f
--- /dev/null
+++ b/Examples/test-suite/php5/import_nomodule_runme.php
@@ -0,0 +1,20 @@
+
diff --git a/Examples/test-suite/php5/li_carrays_cpp_runme.php b/Examples/test-suite/php5/li_carrays_cpp_runme.php
new file mode 100644
index 000000000..3be09ca8c
--- /dev/null
+++ b/Examples/test-suite/php5/li_carrays_cpp_runme.php
@@ -0,0 +1,22 @@
+setitem(0, 7);
+$d->setitem(5, $d->getitem(0) + 3);
+check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/li_carrays_runme.php b/Examples/test-suite/php5/li_carrays_runme.php
new file mode 100644
index 000000000..fbe5cc793
--- /dev/null
+++ b/Examples/test-suite/php5/li_carrays_runme.php
@@ -0,0 +1,22 @@
+setitem(0, 7);
+$d->setitem(5, $d->getitem(0) + 3);
+check::equal($d->getitem(0) + $d->getitem(5), 17., "7+10==17");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/li_factory_runme.php b/Examples/test-suite/php5/li_factory_runme.php
new file mode 100644
index 000000000..6623e2a8c
--- /dev/null
+++ b/Examples/test-suite/php5/li_factory_runme.php
@@ -0,0 +1,22 @@
+radius();
+check::equal($r, 1.5, "r failed");
+
+$point = Geometry::create(Geometry::POINT);
+$w = $point->width();
+check::equal($w, 1.0, "w failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/li_std_string_runme.php b/Examples/test-suite/php5/li_std_string_runme.php
new file mode 100644
index 000000000..ad62247e1
--- /dev/null
+++ b/Examples/test-suite/php5/li_std_string_runme.php
@@ -0,0 +1,31 @@
+MemberString2, "member string 2", "MemberString2 test 1");
+$myStructure->MemberString2 = $s;
+check::equal($myStructure->MemberString2, $s, "MemberString2 test 2");
+check::equal($myStructure->ConstMemberString, "const member string", "ConstMemberString test");
+
+check::equal(Structure::StaticMemberString2(), "static member string 2", "StaticMemberString2 test 1");
+Structure::StaticMemberString2($s);
+check::equal(Structure::StaticMemberString2(), $s, "StaticMemberString2 test 2");
+// below broken ?
+//check::equal(Structure::ConstStaticMemberString(), "const static member string", "ConstStaticMemberString test");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/li_std_vector_member_var_runme.php b/Examples/test-suite/php5/li_std_vector_member_var_runme.php
new file mode 100644
index 000000000..238350352
--- /dev/null
+++ b/Examples/test-suite/php5/li_std_vector_member_var_runme.php
@@ -0,0 +1,30 @@
+x, 0, "Test::x != 0");
+check::equal($t->v->size(), 0, "Test::v.size() != 0");
+
+$t->f(1);
+check::equal($t->x, 1, "Test::x != 1");
+check::equal($t->v->size(), 1, "Test::v.size() != 1");
+
+$t->f(2);
+check::equal($t->x, 3, "Test::x != 3");
+check::equal($t->v->size(), 2, "Test::v.size() != 2");
+
+$t->f(3);
+check::equal($t->x, 6, "Test::x != 6");
+check::equal($t->v->size(), 3, "Test::v.size() != 3");
+
+$T = new T();
+$T->start_t = new S();
+$T->length = 7;
+check::equal($T->start_t->x, 4, "S::x != 4");
+check::equal($T->length, 7, "T::length != 7");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/newobject1_runme.php b/Examples/test-suite/php5/newobject1_runme.php
new file mode 100644
index 000000000..5853a72c0
--- /dev/null
+++ b/Examples/test-suite/php5/newobject1_runme.php
@@ -0,0 +1,19 @@
+makeMore();
+check::equal(get_class($bar), "Foo", "regular failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/overload_rename_runme.php b/Examples/test-suite/php5/overload_rename_runme.php
new file mode 100644
index 000000000..dce4c6cb3
--- /dev/null
+++ b/Examples/test-suite/php5/overload_rename_runme.php
@@ -0,0 +1,19 @@
+
diff --git a/Examples/test-suite/php5/overload_return_type_runme.php b/Examples/test-suite/php5/overload_return_type_runme.php
new file mode 100644
index 000000000..4fa19d22a
--- /dev/null
+++ b/Examples/test-suite/php5/overload_return_type_runme.php
@@ -0,0 +1,13 @@
+foo(1), 0, "");
+check::classname("A", $b->foo("test"));
+
+check::equal(overload_return_type::foo(), 1, "overload_return_type::foo() should be 1");
+check::equal(overload_return_type::bar(), 1, "overload_return_type::bar() should be 1");
+
+?>
diff --git a/Examples/test-suite/php5/php_iterator_runme.php b/Examples/test-suite/php5/php_iterator_runme.php
new file mode 100644
index 000000000..d69a5b385
--- /dev/null
+++ b/Examples/test-suite/php5/php_iterator_runme.php
@@ -0,0 +1,24 @@
+ $v) {
+ $s .= "($k=>$v)";
+}
+check::equal($s, '(0=>2)(1=>3)(2=>4)', 'Simple iteration failed');
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/pointer_reference_runme.php b/Examples/test-suite/php5/pointer_reference_runme.php
new file mode 100644
index 000000000..52946177e
--- /dev/null
+++ b/Examples/test-suite/php5/pointer_reference_runme.php
@@ -0,0 +1,18 @@
+value, 10, "pointer_reference::get() failed");
+
+$ss = new Struct(20);
+pointer_reference::set($ss);
+$i = Struct::instance();
+check::equal($i->value, 20, "pointer_reference::set() failed");
+
+check::equal(pointer_reference::overloading(1), 111, "overload test 1 failed");
+check::equal(pointer_reference::overloading($ss), 222, "overload test 2 failed");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/prefix_runme.php b/Examples/test-suite/php5/prefix_runme.php
new file mode 100644
index 000000000..ead064f5b
--- /dev/null
+++ b/Examples/test-suite/php5/prefix_runme.php
@@ -0,0 +1,18 @@
+get_self();
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/primitive_ref_runme.php b/Examples/test-suite/php5/primitive_ref_runme.php
new file mode 100644
index 000000000..263a28074
--- /dev/null
+++ b/Examples/test-suite/php5/primitive_ref_runme.php
@@ -0,0 +1,34 @@
+
diff --git a/Examples/test-suite/php5/rename_scope_runme.php b/Examples/test-suite/php5/rename_scope_runme.php
new file mode 100644
index 000000000..df620d796
--- /dev/null
+++ b/Examples/test-suite/php5/rename_scope_runme.php
@@ -0,0 +1,16 @@
+
diff --git a/Examples/test-suite/php5/skel.php b/Examples/test-suite/php5/skel.php
new file mode 100644
index 000000000..780a999ed
--- /dev/null
+++ b/Examples/test-suite/php5/skel.php
@@ -0,0 +1,15 @@
+
diff --git a/Examples/test-suite/php5/smart_pointer_rename_runme.php b/Examples/test-suite/php5/smart_pointer_rename_runme.php
new file mode 100644
index 000000000..26692dde5
--- /dev/null
+++ b/Examples/test-suite/php5/smart_pointer_rename_runme.php
@@ -0,0 +1,27 @@
+ftest1(1),"foo->ftest1");
+check::equal(2,$foo->ftest2(1,2),"foo->ftest2");
+
+# check bar's ftest1, ftest2, ftest
+check::equal(1,$bar->ftest1(1),"bar->ftest1");
+check::equal(2,$bar->ftest2(1,2),"bar->ftest2");
+check::equal(3,$bar->test(),"bar->test");
+
+# check deref returns foo
+check::classname("foo",$bar->__deref__());
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/swig_exception_runme.php b/Examples/test-suite/php5/swig_exception_runme.php
new file mode 100644
index 000000000..76641996e
--- /dev/null
+++ b/Examples/test-suite/php5/swig_exception_runme.php
@@ -0,0 +1,33 @@
+throwException();
+ check::fail("Exception wasn't thrown");
+} catch (Exception $e) {
+ if ($e->getMessage() != "OK") {
+ check::fail("Exception getMessage() should be \"OK\", actually \"".$e->getMessage()."\"");
+ }
+}
+
+# ----- Delete everything -----
+
+$c = NULL;
+$s = NULL;
+$e = NULL;
+
+if (Shape::nshapes() != 0) {
+ check::fail("Shape::nshapes() should be 0, actually ".Shape::nshapes());
+}
+
+?>
diff --git a/Examples/test-suite/php5/sym_runme.php b/Examples/test-suite/php5/sym_runme.php
new file mode 100644
index 000000000..483aaa980
--- /dev/null
+++ b/Examples/test-suite/php5/sym_runme.php
@@ -0,0 +1,22 @@
+hulahoops(),"flim-jam","flim()->hulahoops==flim-jam");
+check::equal($flim->jar(),"flim-jar","flim()->jar==flim-jar");
+check::equal($flam->jam(),"flam-jam","flam()->jam==flam-jam");
+check::equal($flam->jar(),"flam-jar","flam()->jar==flam-jar");
+
+check::done();
+?>
diff --git a/Examples/test-suite/php5/template_arg_typename_runme.php b/Examples/test-suite/php5/template_arg_typename_runme.php
new file mode 100644
index 000000000..7d60285e3
--- /dev/null
+++ b/Examples/test-suite/php5/template_arg_typename_runme.php
@@ -0,0 +1,18 @@
+
diff --git a/Examples/test-suite/php5/template_construct_runme.php b/Examples/test-suite/php5/template_construct_runme.php
new file mode 100644
index 000000000..3a3986f7e
--- /dev/null
+++ b/Examples/test-suite/php5/template_construct_runme.php
@@ -0,0 +1,11 @@
+
diff --git a/Examples/test-suite/php5/tests.php b/Examples/test-suite/php5/tests.php
new file mode 100644
index 000000000..d3fd66868
--- /dev/null
+++ b/Examples/test-suite/php5/tests.php
@@ -0,0 +1,237 @@
+
diff --git a/Examples/test-suite/php5/threads_exception_runme.php b/Examples/test-suite/php5/threads_exception_runme.php
new file mode 100644
index 000000000..9e4d04e10
--- /dev/null
+++ b/Examples/test-suite/php5/threads_exception_runme.php
@@ -0,0 +1,43 @@
+unknown();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ A * exception thrown', '');
+}
+
+try {
+ $t->simple();
+} catch (Exception $e) {
+ check::equal($e->getCode(), 37, '');
+}
+
+try {
+ $t->message();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'I died.', '');
+}
+
+try {
+ $t->hosed();
+} catch (Exception $e) {
+ check::equal($e->getMessage(), 'C++ Exc exception thrown', '');
+}
+
+foreach (Array(1,2,3,4) as $i) {
+ try {
+ $t->multi($i);
+ } catch (Exception $e) {
+ }
+}
diff --git a/Examples/test-suite/php5/typedef_reference_runme.php b/Examples/test-suite/php5/typedef_reference_runme.php
new file mode 100644
index 000000000..88a70f8d3
--- /dev/null
+++ b/Examples/test-suite/php5/typedef_reference_runme.php
@@ -0,0 +1,13 @@
+
diff --git a/Examples/test-suite/php5/typemap_ns_using_runme.php b/Examples/test-suite/php5/typemap_ns_using_runme.php
new file mode 100644
index 000000000..6a599f008
--- /dev/null
+++ b/Examples/test-suite/php5/typemap_ns_using_runme.php
@@ -0,0 +1,9 @@
+
diff --git a/Examples/test-suite/php5/using1_runme.php b/Examples/test-suite/php5/using1_runme.php
new file mode 100644
index 000000000..51841bc78
--- /dev/null
+++ b/Examples/test-suite/php5/using1_runme.php
@@ -0,0 +1,9 @@
+
diff --git a/Examples/test-suite/php5/using2_runme.php b/Examples/test-suite/php5/using2_runme.php
new file mode 100644
index 000000000..391a98f52
--- /dev/null
+++ b/Examples/test-suite/php5/using2_runme.php
@@ -0,0 +1,9 @@
+
diff --git a/Examples/test-suite/php5/valuewrapper_base_runme.php b/Examples/test-suite/php5/valuewrapper_base_runme.php
new file mode 100644
index 000000000..6a1abdbd2
--- /dev/null
+++ b/Examples/test-suite/php5/valuewrapper_base_runme.php
@@ -0,0 +1,13 @@
+
diff --git a/Examples/test-suite/php5/virtual_vs_nonvirtual_base_runme.php b/Examples/test-suite/php5/virtual_vs_nonvirtual_base_runme.php
new file mode 100644
index 000000000..0d4aa3d5f
--- /dev/null
+++ b/Examples/test-suite/php5/virtual_vs_nonvirtual_base_runme.php
@@ -0,0 +1,11 @@
+
+
+require "tests.php";
+require "virtual_vs_nonvirtual_base.php";
+
+$fail = new SimpleClassFail();
+$work = new SimpleClassWork();
+
+check::equal($work->getInner()->get(), $fail->getInner()->get(), "should both be 10");
+
+?>
diff --git a/Examples/test-suite/php5/wrapmacro_runme.php b/Examples/test-suite/php5/wrapmacro_runme.php
new file mode 100644
index 000000000..f32da990e
--- /dev/null
+++ b/Examples/test-suite/php5/wrapmacro_runme.php
@@ -0,0 +1,12 @@
+
diff --git a/Lib/allkw.swg b/Lib/allkw.swg
index 563190e19..b9413191f 100644
--- a/Lib/allkw.swg
+++ b/Lib/allkw.swg
@@ -24,6 +24,7 @@
%include
%include
%include
+%include
%include
%include
%include
diff --git a/Lib/cdata.i b/Lib/cdata.i
index b9b8e1887..730ecccfb 100644
--- a/Lib/cdata.i
+++ b/Lib/cdata.i
@@ -29,13 +29,20 @@ typedef struct SWIGCDATA {
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
-#elif SWIGPHP
+#elif SWIGPHP5
%typemap(out) SWIGCDATA {
ZVAL_STRINGL($result, $1.data, $1.len, 1);
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
+#elif SWIGPHP7
+
+%typemap(out) SWIGCDATA {
+ ZVAL_STRINGL($result, $1.data, $1.len);
+}
+%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
+
#elif SWIGJAVA
%apply (char *STRING, int LENGTH) { (const void *indata, int inlen) }
diff --git a/Lib/exception.i b/Lib/exception.i
index c8509987b..da0d56cdd 100644
--- a/Lib/exception.i
+++ b/Lib/exception.i
@@ -12,13 +12,20 @@
%insert("runtime") "swigerrors.swg"
-#ifdef SWIGPHP
+#ifdef SWIGPHP5
%{
#include "zend_exceptions.h"
#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); goto thrown; } while (0)
%}
#endif
+#ifdef SWIGPHP7
+%{
+#include "zend_exceptions.h"
+#define SWIG_exception(code, msg) do { zend_throw_exception(NULL, (char*)msg, code); goto thrown; } while (0)
+%}
+#endif
+
#ifdef SWIGGUILE
%{
SWIGINTERN void SWIG_exception_ (int code, const char *msg,
diff --git a/Lib/php/const.i b/Lib/php/const.i
index 061ba99a2..644fd2c78 100644
--- a/Lib/php/const.i
+++ b/Lib/php/const.i
@@ -33,18 +33,13 @@
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE [] {
- zval *z_var;
zend_constant c;
- size_t len = sizeof("$symname") - 1;
- MAKE_STD_ZVAL(z_var);
- SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0);
- c.value = *z_var;
+ SWIG_SetPointerZval(&c.value, (void*)$value, $1_descriptor, 0);
zval_copy_ctor(&c.value);
- c.name = zend_strndup("$symname", len);
- c.name_len = len+1;
- c.flags = CONST_CS | CONST_PERSISTENT;
+ c.name = zend_string_init("$symname", sizeof("$symname") - 1, 0);
+ c.flags = CONST_CS;
c.module_number = module_number;
- zend_register_constant( &c TSRMLS_CC );
+ zend_register_constant(&c);
}
/* Handled as a global variable. */
diff --git a/Lib/php/director.swg b/Lib/php/director.swg
index 638a1697d..ea0eba8ac 100644
--- a/Lib/php/director.swg
+++ b/Lib/php/director.swg
@@ -77,30 +77,30 @@ namespace Swig {
class Director {
protected:
- zval *swig_self;
+ // "mutable" so we can get a non-const pointer to it in const methods.
+ mutable zval swig_self;
typedef std::map swig_ownership_map;
mutable swig_ownership_map swig_owner;
-#ifdef ZTS
- // Store the ZTS context so it's available when C++ calls back to PHP.
- void *** swig_zts_ctx;
-#endif
public:
- Director(zval *self TSRMLS_DC) : swig_self(self) {
- TSRMLS_SET_CTX(swig_zts_ctx);
+ Director(zval *self) {
+ ZVAL_COPY_VALUE(&swig_self, self);
}
- static bool swig_is_overridden_method(char *cname, char *lc_fname TSRMLS_DC) {
- zend_class_entry **ce;
- zend_function *mptr;
-
- if (zend_lookup_class(cname, strlen(cname), &ce TSRMLS_CC) != SUCCESS) {
- return false;
+ static bool swig_is_overridden_method(const char *cname, const char *lc_fname) {
+ bool result = false;
+ zend_string * cname_str = zend_string_init(cname, strlen(cname), 0);
+ zend_class_entry *ce = zend_lookup_class(cname_str);
+ if (ce) {
+ zval * mptr = zend_hash_str_find(&ce->function_table, lc_fname, strlen(lc_fname));
+ if (mptr) {
+ // common.scope points to zend_class_entry for the declaring class,
+ // and there's only one of those per class, so we can just use a
+ // pointer compare here.
+ result = Z_FUNC_P(mptr)->common.scope != ce;
+ }
}
- if (zend_hash_find(&(*ce)->function_table, lc_fname, strlen(lc_fname) + 1, (void **) &mptr) != SUCCESS) {
- return false;
- }
- // common.scope points to the declaring class
- return strcmp(mptr->common.scope->name, cname);
+ zend_string_release(cname_str);
+ return result;
}
template
@@ -116,8 +116,8 @@ namespace Swig {
protected:
std::string swig_msg;
public:
- DirectorException(int code, const char *hdr, const char *msg TSRMLS_DC) : swig_msg(hdr) {
- if (msg[0]) {
+ DirectorException(int code, const char *hdr, const char *msg) : swig_msg(hdr) {
+ if (msg && msg[0]) {
swig_msg += " ";
swig_msg += msg;
}
@@ -132,20 +132,20 @@ namespace Swig {
return swig_msg.c_str();
}
- static void raise(int code, const char *hdr, const char *msg TSRMLS_DC) {
- throw DirectorException(code, hdr, msg TSRMLS_CC);
+ static void raise(int code, const char *hdr, const char *msg) {
+ throw DirectorException(code, hdr, msg);
}
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public DirectorException {
public:
- DirectorPureVirtualException(const char *msg TSRMLS_DC)
- : DirectorException(E_ERROR, "SWIG director pure virtual method called", msg TSRMLS_CC) {
+ DirectorPureVirtualException(const char *msg)
+ : DirectorException(E_ERROR, "SWIG director pure virtual method called", msg) {
}
- static void raise(const char *msg TSRMLS_DC) {
- throw DirectorPureVirtualException(msg TSRMLS_CC);
+ static void raise(const char *msg) {
+ throw DirectorPureVirtualException(msg);
}
};
@@ -153,18 +153,18 @@ namespace Swig {
class DirectorMethodException : public DirectorException
{
public:
- DirectorMethodException(const char *msg TSRMLS_DC)
- : DirectorException(E_ERROR, "SWIG director method error", msg TSRMLS_CC) {
+ DirectorMethodException()
+ : DirectorException(E_ERROR, "SWIG director method error", NULL) {
}
- static void raise(const char *msg TSRMLS_DC) {
- throw DirectorMethodException(msg TSRMLS_CC);
+ DirectorMethodException(const char *msg)
+ : DirectorException(E_ERROR, "SWIG director method error", msg) {
+ }
+
+ static void raise(const char *msg) {
+ throw DirectorMethodException(msg);
}
};
}
-// DirectorMethodException() is documented to be callable with no parameters
-// so use a macro to insert TSRMLS_CC so any ZTS context gets passed.
-#define DirectorMethodException() DirectorMethodException("" TSRMLS_CC)
-
#endif
diff --git a/Lib/php/globalvar.i b/Lib/php/globalvar.i
index a3e99f510..a5fd779ab 100644
--- a/Lib/php/globalvar.i
+++ b/Lib/php/globalvar.i
@@ -6,27 +6,20 @@
%typemap(varinit) char *
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_STRING;
- if($1) {
- z_var->value.str.val = estrdup($1);
- z_var->value.str.len = strlen($1);
+ zval z_var;
+ if ($1) {
+ ZVAL_STRING(&z_var, $1);
} else {
- z_var->value.str.val = 0;
- z_var->value.str.len = 0;
+ ZVAL_STR(&z_var, ZSTR_EMPTY_ALLOC());
}
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) char []
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_STRING;
- z_var->value.str.val = estrdup($1);
- z_var->value.str.len = strlen($1);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
+ zval z_var;
+ ZVAL_STRING(&z_var, $1);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) int,
@@ -40,136 +33,98 @@
unsigned char,
enum SWIGTYPE
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_LONG;
- z_var->value.lval = (long)$1;
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
+ zval z_var;
+ ZVAL_LONG(&z_var, (long)$1);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) bool
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_BOOL;
- z_var->value.lval = ($1)?1:0;
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var, sizeof(zval *), NULL);
+ zval z_var;
+ ZVAL_BOOL(&z_var, ($1)?1:0);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) float, double
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_DOUBLE;
- z_var->value.dval = $1;
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var,
- sizeof(zval *), NULL);
+ zval z_var;
+ ZVAL_DOUBLE(&z_var, (double)$1);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) char
{
- zval *z_var;
- char c[2];
- MAKE_STD_ZVAL(z_var);
- c[0] = $1;
- c[1] = 0;
- z_var->type = IS_STRING;
- z_var->value.str.val = estrndup(c, 1);
- z_var->value.str.len = 1;
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var,
- sizeof(zval *), NULL);
+ zval z_var;
+ char c = $1;
+ ZVAL_STRINGL(&z_var, &c, 1);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) SWIGTYPE *, SWIGTYPE []
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, 0);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void *)&z_var,
- sizeof(zval *), NULL);
+ zval z_var;
+ SWIG_SetPointerZval(&z_var, (void*)$1, $1_descriptor, 0);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&
{
- zval *z_var;
-
- MAKE_STD_ZVAL(z_var);
- SWIG_SetPointerZval(z_var, (void*)&$1, $&1_descriptor, 0);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var,
- sizeof(zval *), NULL);
+ zval z_var;
+ SWIG_SetPointerZval(&z_var, (void*)&$1, $&1_descriptor, 0);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit) char [ANY]
{
- zval *z_var;
- MAKE_STD_ZVAL(z_var);
- z_var->type = IS_STRING;
- ZVAL_STRINGL(z_var,(char*)$1, $1_dim0, 1);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
+ zval z_var;
+ /* varinit char [ANY] */
+ ZVAL_STRINGL(&z_var, $1, $1_dim0);
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &z_var);
}
%typemap(varinit, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
+ zval resource;
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
- zval * resource;
- MAKE_STD_ZVAL(resource);
- ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
+ ZVAL_RES(&resource, zend_register_resource(p, swig_member_ptr));
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &resource);
}
%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- convert_to_long_ex(z_var);
- if ($1 != ($1_ltype)((*z_var)->value.lval)) {
- $1 = Z_LVAL_PP(z_var);
- }
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ $1 = zval_get_long(z_var);
}
%typemap(varin) bool
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- convert_to_boolean_ex(z_var);
- if ($1 != ($1_ltype)((*z_var)->value.lval)) {
- $1 = Z_LVAL_PP(z_var);
- }
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ convert_to_boolean(z_var);
+ $1 = (Z_TYPE_P(z_var) == IS_TRUE);
}
%typemap(varin) double,float
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- convert_to_double_ex(z_var);
- if ($1 != ($1_ltype)((*z_var)->value.dval)) {
- $1 = Z_DVAL_PP(z_var);
- }
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ $1 = zval_get_double(z_var);
}
%typemap(varin) char
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- convert_to_string_ex(z_var);
- if ($1 != *((*z_var)->value.str.val)) {
- $1 = *((*z_var)->value.str.val);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ convert_to_string(z_var);
+ if ($1 != Z_STRVAL_P(z_var)[0]) {
+ $1 = Z_STRVAL_P(z_var)[0];
}
}
%typemap(varin) char *
{
- zval **z_var;
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
char *s1;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- convert_to_string_ex(z_var);
- s1 = Z_STRVAL_PP(z_var);
+ convert_to_string(z_var);
+ s1 = Z_STRVAL_P(z_var);
if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) {
if (s1)
$1 = estrdup(s1);
@@ -181,11 +136,9 @@
%typemap(varin) SWIGTYPE []
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
if($1) {
- SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, $owner);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, $owner);
}
}
@@ -194,8 +147,8 @@
zval **z_var;
char *s1;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- s1 = Z_STRVAL_PP(z_var);
+ zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1, (void**)&z_var);
+ s1 = Z_STRVAL_P(z_var);
if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) {
if (s1)
strncpy($1, s1, $1_dim0);
@@ -204,11 +157,11 @@
%typemap(varin) SWIGTYPE
{
- zval **z_var;
+ zval *z_var;
$&1_ltype _temp;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if (SWIG_ConvertPtr(*z_var, (void**)&_temp, $&1_descriptor, 0) < 0) {
+ z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ if (SWIG_ConvertPtr(z_var, (void**)&_temp, $&1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR,"Type error in value of $symname. Expected $&1_descriptor");
}
@@ -218,11 +171,11 @@
%typemap(varin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&
{
- zval **z_var;
+ zval *z_var;
$1_ltype _temp;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if (SWIG_ConvertPtr(*z_var, (void **)&_temp, $1_descriptor, 0) < 0) {
+ z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ if (SWIG_ConvertPtr(z_var, (void **)&_temp, $1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR,"Type error in value of $symname. Expected $&1_descriptor");
}
@@ -231,10 +184,8 @@
%typemap(varin, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ void * p = (void*)zend_fetch_resource_ex(z_var, SWIG_MEMBER_PTR, swig_member_ptr);
memcpy(&$1, p, sizeof($1));
}
@@ -248,114 +199,96 @@
unsigned char,
enum SWIGTYPE
{
- zval **z_var;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if($1 != ($1_ltype)((*z_var)->value.lval)) {
- (*z_var)->value.lval = (long)$1;
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ if ($1 != ($1_ltype)Z_LVAL_P(z_var)) {
+ z_var->value.lval = (long)$1;
}
}
//SAMFIX need to cast zval->type, what if zend-hash_find fails? etc?
%typemap(varout) bool
{
- zval **z_var;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if($1 != ($1_ltype)((*z_var)->value.lval)) {
- (*z_var)->value.lval = (long)$1;
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ if ($1 != ($1_ltype)Z_LVAL_P(z_var)) {
+ z_var->value.lval = (long)$1;
}
}
%typemap(varout) double, float
{
- zval **z_var;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if($1 != ($1_ltype)((*z_var)->value.dval)) {
- (*z_var)->value.dval = (double)$1;
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ if ($1 != ($1_ltype)Z_DVAL_P(z_var)) {
+ z_var->value.dval = (double)$1;
}
}
%typemap(varout) char
{
- zval **z_var;
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if($1 != *((*z_var)->value.str.val)) {
- char c[2];
- efree((*z_var)->value.str.val);
- c[0] = $1;
- c[1] = 0;
- (*z_var)->value.str.val = estrdup(c);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ char c = $1;
+ if ($1 != Z_STRVAL_P(z_val)[0]) {
+ ZVAL_STRING(z_var, &c);
}
}
%typemap(varout) char *
{
- zval **z_var;
- char *s1;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- s1 = Z_STRVAL_PP(z_var);
- if((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) {
- if(s1)
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ const char *s1 = Z_STRVAL_P(z_var);
+ if ((s1 == NULL) || ($1 == NULL) || strcmp(s1, $1)) {
+ if (s1)
efree(s1);
- if($1) {
- (*z_var)->value.str.val = estrdup($1);
- (*z_var)->value.str.len = strlen($1) + 1;
+ if ($1) {
+ (z_var)->value.str.val = estrdup($1);
+ (z_var)->value.str.len = strlen($1) + 1;
} else {
- (*z_var)->value.str.val = 0;
- (*z_var)->value.str.len = 0;
+ (z_var)->value.str.val = 0;
+ (z_var)->value.str.len = 0;
}
}
}
%typemap(varout) SWIGTYPE
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- SWIG_SetPointerZval(*z_var, (void*)&$1, $&1_descriptor, 0);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ SWIG_SetPointerZval(z_var, (void*)&$1, $&1_descriptor, 0);
}
%typemap(varout) SWIGTYPE []
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- if($1)
- SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
+ if($1) {
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, 0);
+ }
}
%typemap(varout) char [ANY]
{
- zval **z_var;
- char *s1;
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ const char *s1 = Z_STRVAL_P(z_var);
deliberate error cos this code looks bogus to me
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- s1 = Z_STRVAL_PP(z_var);
- if((s1 == NULL) || strcmp(s1, $1)) {
- if($1) {
- (*z_var)->value.str.val = estrdup($1);
- (*z_var)->value.str.len = strlen($1) + 1;
+ if ((s1 == NULL) || strcmp(s1, $1)) {
+ if ($1) {
+ (z_var)->value.str.val = estrdup($1);
+ (z_var)->value.str.len = strlen($1) + 1;
} else {
- (*z_var)->value.str.val = 0;
- (*z_var)->value.str.len = 0;
+ (z_var)->value.str.val = 0;
+ (z_var)->value.str.len = 0;
}
}
}
%typemap(varout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&
{
- zval **z_var;
-
- zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
- SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
+ zval *z_var = zend_hash_str_find(&EG(symbol_table), "$1", sizeof("$1") - 1);
+ SWIG_SetPointerZval(z_var, (void*)$1, $1_descriptor, 0);
}
%typemap(varout, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
+ zval resource;
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
- zval * resource;
- MAKE_STD_ZVAL(resource);
- ZEND_REGISTER_RESOURCE(resource, p, swig_member_ptr);
- zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
+ ZVAL_RES(&resource, zend_register_resource(p, swig_member_ptr));
+ zend_hash_str_add(&EG(symbol_table), "$1", sizeof("$1") - 1, &resource);
}
diff --git a/Lib/php/php.swg b/Lib/php/php.swg
index 535c7d347..c9b9a5217 100644
--- a/Lib/php/php.swg
+++ b/Lib/php/php.swg
@@ -71,72 +71,72 @@
// char array can be in/out, though the passed string may not be big enough...
// so we have to size it
%typemap(in) char[ANY]
-{
- convert_to_string_ex($input);
- $1 = ($1_ltype) Z_STRVAL_PP($input);
-}
+%{
+ convert_to_string(&$input);
+ $1 = ($1_ltype) Z_STRVAL($input);
+%}
-%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) {
- convert_to_string_ex($input);
- $1 = ($1_ltype) Z_STRVAL_PP($input);
- $2 = ($2_ltype) Z_STRLEN_PP($input);
-}
+%typemap(in) (char *STRING, int LENGTH), (char *STRING, size_t LENGTH) %{
+ convert_to_string(&$input);
+ $1 = ($1_ltype) Z_STRVAL($input);
+ $2 = ($2_ltype) Z_STRLEN($input);
+%}
/* Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE ($&1_ltype tmp)
-{
- if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
$1 = *tmp;
-}
+%}
%typemap(directorout) SWIGTYPE ($&1_ltype tmp)
-{
+%{
/* If exit was via exception, PHP NULL is returned so skip the conversion. */
if (!EG(exception)) {
- if(SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL)
+ if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL)
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
$result = *tmp;
}
-}
+%}
%typemap(in) SWIGTYPE *,
SWIGTYPE []
-{
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
}
-}
+%}
%typemap(in) SWIGTYPE &
-{
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
}
-}
+%}
%typemap(in) SWIGTYPE &&
-{
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $1_descriptor");
}
-}
+%}
%typemap(in) SWIGTYPE *const& ($*ltype temp)
-{
- if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &temp, $*1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor");
}
$1 = ($1_ltype)&temp;
-}
+%}
%typemap(in) SWIGTYPE *DISOWN
-{
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
-}
+%}
%typemap(argout) SWIGTYPE *,
SWIGTYPE [],
@@ -144,14 +144,14 @@
SWIGTYPE &&;
%typemap(in) void *
-{
- if(SWIG_ConvertPtr(*$input, (void **) &$1, 0, 0) < 0) {
+%{
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, 0, 0) < 0) {
/* Allow NULL from php for void* */
- if ((*$input)->type==IS_NULL) $1=0;
+ if (Z_ISNULL($input)) $1=0;
else
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
-}
+%}
/* Special case when void* is passed by reference so it can be made to point
to opaque api structs */
@@ -160,9 +160,9 @@
{
/* If they pass NULL by reference, make it into a void*
This bit should go in arginit if arginit support init-ing scripting args */
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) {
/* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
- if (!((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input))) {
+ if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) {
/* wasn't a pre/ref/thing, OR anything like an int thing */
SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname.");
}
@@ -181,11 +181,11 @@
}
%typemap(argout) void **,
void *&
-{
+%{
if (force$argnum) {
- SWIG_SetPointerZval( *$input, (void*) ptr$argnum, $*1_descriptor, 1);
+ SWIG_SetPointerZval(&$input, (void*) ptr$argnum, $*1_descriptor, 1);
}
-}
+%}
/* Typemap for output values */
@@ -199,35 +199,33 @@
unsigned char,
bool,
size_t
-{
- ZVAL_LONG(return_value,$1);
-}
+%{
+ RETVAL_LONG($1);
+%}
%typemap(out) enum SWIGTYPE
-{
- ZVAL_LONG(return_value, (long)$1);
-}
+%{
+ RETVAL_LONG((long)$1);
+%}
%typemap(out) long long
%{
if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) {
- return_value->value.lval = (long)($1);
- return_value->type = IS_LONG;
+ RETVAL_LONG((long)($1));
} else {
char temp[256];
sprintf(temp, "%lld", (long long)$1);
- ZVAL_STRING(return_value, temp, 1);
+ RETVAL_STRING(temp);
}
%}
%typemap(out) unsigned long long
%{
if ($1 <= (unsigned long long)LONG_MAX) {
- return_value->value.lval = (long)($1);
- return_value->type = IS_LONG;
+ RETVAL_LONG((long)($1));
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)$1);
- ZVAL_STRING(return_value, temp, 1);
+ RETVAL_STRING(temp);
}
%}
@@ -241,40 +239,38 @@
const unsigned char &,
const bool &,
const size_t &
-{
- ZVAL_LONG(return_value,*$1);
-}
+%{
+ RETVAL_LONG(*$1);
+%}
%typemap(out) const enum SWIGTYPE &
-{
- ZVAL_LONG(return_value, (long)*$1);
-}
+%{
+ RETVAL_LONG((long)*$1);
+%}
%typemap(out) const enum SWIGTYPE &&
-{
- ZVAL_LONG(return_value, (long)*$1);
-}
+%{
+ RETVAL_LONG((long)*$1);
+%}
%typemap(out) const long long &
%{
if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) {
- return_value->value.lval = (long)(*$1);
- return_value->type = IS_LONG;
+ RETVAL_LONG((long)(*$1));
} else {
char temp[256];
sprintf(temp, "%lld", (long long)(*$1));
- ZVAL_STRING(return_value, temp, 1);
+ RETVAL_STRING(temp);
}
%}
%typemap(out) const unsigned long long &
%{
if (*$1 <= (unsigned long long)LONG_MAX) {
- return_value->value.lval = (long)(*$1);
- return_value->type = IS_LONG;
+ RETVAL_LONG((long)(*$1));
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)(*$1));
- ZVAL_STRING(return_value, temp, 1);
+ RETVAL_STRING(temp);
}
%}
@@ -288,85 +284,85 @@
unsigned char,
size_t,
enum SWIGTYPE
-{
+%{
ZVAL_LONG($input,$1);
-}
+%}
%typemap(directorin) enum SWIGTYPE
-{
+%{
ZVAL_LONG($input, (long)$1_name);
-}
+%}
%typemap(directorin) char *, char []
-{
+%{
if(!$1) {
ZVAL_NULL($input);
} else {
- ZVAL_STRING($input, (char *)$1, 1);
+ ZVAL_STRING($input, (const char*)$1);
}
-}
+%}
%typemap(out) bool
-{
- ZVAL_BOOL(return_value,($1)?1:0);
-}
+%{
+ RETVAL_BOOL(($1) ? 1 : 0);
+%}
%typemap(out) const bool &
-{
- ZVAL_BOOL(return_value,(*$1)?1:0);
-}
+%{
+ RETVAL_BOOL((*$1) ? 1 : 0);
+%}
%typemap(directorin) bool
-{
- ZVAL_BOOL($input,($1)?1:0);
-}
+%{
+ ZVAL_BOOL($input, ($1) ? 1 : 0);
+%}
%typemap(out) float,
double
-{
- ZVAL_DOUBLE(return_value,$1);
-}
+%{
+ RETVAL_DOUBLE($1);
+%}
%typemap(out) const float &,
const double &
-{
- ZVAL_DOUBLE(return_value,*$1);
-}
+%{
+ RETVAL_DOUBLE(*$1);
+%}
%typemap(directorin) float,
double
-{
- ZVAL_DOUBLE($input,$1);
-}
+%{
+ ZVAL_DOUBLE($input, $1);
+%}
%typemap(out) char
-{
- ZVAL_STRINGL(return_value,&$1, 1, 1);
-}
+%{
+ RETVAL_STRINGL(&$1, 1);
+%}
%typemap(out) const char &
-{
- ZVAL_STRINGL(return_value,&*$1, 1, 1);
-}
+%{
+ RETVAL_STRINGL(&*$1, 1);
+%}
%typemap(out) char *,
char []
-{
- if(!$1) {
- ZVAL_NULL(return_value);
- } else {
- ZVAL_STRING(return_value, (char *)$1, 1);
- }
-}
+%{
+ if (!$1) {
+ RETVAL_NULL();
+ } else {
+ RETVAL_STRING((const char *)$1);
+ }
+%}
%typemap(out) char *&
-{
- if(!*$1) {
- ZVAL_NULL(return_value);
- } else {
- ZVAL_STRING(return_value, (char *)*$1, 1);
- }
-}
+%{
+ if (!*$1) {
+ RETVAL_NULL();
+ } else {
+ RETVAL_STRING((const char *)*$1);
+ }
+%}
%typemap(out) SWIGTYPE *,
SWIGTYPE [],
@@ -393,12 +389,12 @@
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
- ZEND_REGISTER_RESOURCE(return_value, p, swig_member_ptr);
+ RETVAL_RES(zend_register_resource(p, swig_member_ptr));
}
%typemap(in, fragment="swig_php_init_member_ptr") SWIGTYPE (CLASS::*)
{
- void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, swig_member_ptr);
+ void * p = (void*)zend_fetch_resource_ex(&$input, SWIG_MEMBER_PTR, swig_member_ptr);
memcpy(&$1, p, sizeof($1));
}
@@ -424,9 +420,9 @@
#endif
%typemap(directorin) SWIGTYPE
-{
+%{
SWIG_SetPointerZval($input, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, 1|2);
-}
+%}
%typemap(out) void "";
@@ -434,7 +430,7 @@
{
int len = 0;
while (len < $1_dim0 && $1[len]) ++len;
- RETVAL_STRINGL($1, len, 1);
+ RETVAL_STRINGL($1, len);
}
// This typecheck does hard checking for proper argument type. If you want
@@ -442,7 +438,13 @@
// it yourself before passing it (e.g. (string)4.7 or (int)"6").
%define %php_typecheck(_type,_prec,is)
%typemap(typecheck,precedence=_prec) _type, const _type &
- " $1 = (Z_TYPE_PP($input) == is); "
+ " $1 = (Z_TYPE($input) == is);"
+%enddef
+
+// Like %php_typecheck but allows either of two values.
+%define %php_typecheck2(_type,_prec,is1,is2)
+%typemap(typecheck,precedence=_prec) _type, const _type &
+ " $1 = (Z_TYPE($input) == is1 || Z_TYPE($input) == is2);"
%enddef
%php_typecheck(int,SWIG_TYPECHECK_INTEGER,IS_LONG)
@@ -457,18 +459,18 @@
%php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG)
%php_typecheck(size_t,SWIG_TYPECHECK_SIZE,IS_LONG)
%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INTEGER,IS_LONG)
-%php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL)
+%php_typecheck2(bool,SWIG_TYPECHECK_BOOL,IS_TRUE,IS_FALSE)
%php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE)
%php_typecheck(double,SWIG_TYPECHECK_DOUBLE,IS_DOUBLE)
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char []
- " $1 = (Z_TYPE_PP($input) == IS_STRING); "
+ " $1 = (Z_TYPE($input) == IS_STRING); "
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
void *tmp;
- _v = (SWIG_ConvertPtr(*$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
+ _v = (SWIG_ConvertPtr(&$input, (void **)&tmp, $&1_descriptor, 0) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER)
@@ -479,19 +481,19 @@
SWIGTYPE *const&
{
void *tmp;
- _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0);
+ _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $1_descriptor, 0) >= 0);
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
{
void *tmp;
- _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $*1_descriptor, 0) >= 0);
+ _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, $*1_descriptor, 0) >= 0);
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
{
void *tmp;
- _v = (SWIG_ConvertPtr(*$input, (void**)&tmp, 0, 0) >= 0);
+ _v = (SWIG_ConvertPtr(&$input, (void**)&tmp, 0, 0) >= 0);
}
/* Exception handling */
@@ -501,19 +503,19 @@
short,
unsigned int,
unsigned long,
- unsigned short {
- zend_throw_exception(NULL, const_cast("C++ $1_type exception thrown"), $1 TSRMLS_CC);
+ unsigned short %{
+ zend_throw_exception(NULL, "C++ $1_type exception thrown", $1);
return;
-}
+%}
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY] %{
(void)$1;
- zend_throw_exception(NULL, const_cast("C++ $1_type exception thrown"), 0 TSRMLS_CC);
+ zend_throw_exception(NULL, "C++ $1_type exception thrown", 0);
return;
%}
%typemap(throws) char * %{
- zend_throw_exception(NULL, const_cast($1), 0 TSRMLS_CC);
+ zend_throw_exception(NULL, $1, 0);
return;
%}
diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg
index 6e5cc29d2..7144f42a3 100644
--- a/Lib/php/phpinit.swg
+++ b/Lib/php/phpinit.swg
@@ -10,16 +10,16 @@
SWIG_InitializeModule(0);
%}
-%fragment("swig_php_init_member_ptr2", "header") {
-#define SWIG_MEMBER_PTR ((char*)"CLASS::*")
+%fragment("swig_php_init_member_ptr2", "header") %{
+#define SWIG_MEMBER_PTR "CLASS::*"
-static void swig_member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- efree(rsrc->ptr);
+static void swig_member_ptr_dtor(zend_resource *res) {
+ efree(res->ptr);
}
static int swig_member_ptr = 0;
-}
+%}
-%fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") {
+%fragment("swig_php_init_member_ptr", "init", fragment="swig_php_init_member_ptr2") %{
swig_member_ptr = zend_register_list_destructors_ex(swig_member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number);
-}
+%}
diff --git a/Lib/php/phpkw.swg b/Lib/php/phpkw.swg
index 36e535f52..db451f957 100644
--- a/Lib/php/phpkw.swg
+++ b/Lib/php/phpkw.swg
@@ -661,6 +661,21 @@ PHPCN(generator); // As of PHP 5.5
PHPCN(self);
PHPCN(static);
PHPCN(parent);
+/* http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.other.classes */
+PHPCN(bool); // As of PHP 7.0
+PHPCN(int); // As of PHP 7.0
+PHPCN(float); // As of PHP 7.0
+PHPCN(string); // As of PHP 7.0
+PHPCN(NULL); // As of PHP 7.0
+PHPCN(TRUE); // As of PHP 7.0
+PHPCN(FALSE); // As of PHP 7.0
+PHPCN(resource); // As of PHP 7.0 (currently works but reserved)
+PHPCN(object); // As of PHP 7.0 (currently works but reserved)
+PHPCN(mixed); // As of PHP 7.0 (currently works but reserved)
+PHPCN(numeric); // As of PHP 7.0 (currently works but reserved)
+/* http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.invalid-class-names */
+PHPCN(iterable); // As of PHP 7.1
+PHPCN(void); // As of PHP 7.1
/* From extensions (which of these are actually predefined depends which
* extensions are loaded by default). */
PHPCN(xmlwriter);
diff --git a/Lib/php/phppointers.i b/Lib/php/phppointers.i
index e50ada7ac..d79697b5e 100644
--- a/Lib/php/phppointers.i
+++ b/Lib/php/phppointers.i
@@ -3,19 +3,23 @@
TYPE &REF ($*1_ltype tmp)
%{
/* First Check for SWIG wrapped type */
- if ( ZVAL_IS_NULL( *$input ) ) {
+ if (Z_ISNULL($input)) {
$1 = 0;
- } else if ( PZVAL_IS_REF( *$input ) ) {
+ } else if (Z_ISREF($input)) {
/* Not swig wrapped type, so we check if it's a PHP reference type */
- CONVERT_IN( tmp, $*1_ltype, $input );
+ CONVERT_IN(tmp, $*1_ltype, $input);
$1 = &tmp;
} else {
- SWIG_PHP_Error( E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference) );
+ SWIG_PHP_Error(E_ERROR, SWIG_PHP_Arg_Error_Msg($argnum, Expected a reference));
}
%}
%typemap(argout) TYPE *REF,
TYPE &REF
- "CONVERT_OUT(*$input, tmp$argnum );";
+%{
+ if (Z_ISREF($input)) {
+ CONVERT_OUT(Z_REFVAL($input), tmp$argnum);
+ }
+%}
%enddef
%pass_by_ref( size_t, CONVERT_INT_IN, ZVAL_LONG );
diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg
index 0021a90e8..b697e2761 100644
--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -14,62 +14,22 @@ extern "C" {
#include "ext/standard/php_string.h"
#include /* for abort(), used in generated code. */
-#ifdef ZEND_RAW_FENTRY
-/* ZEND_RAW_FENTRY was added somewhere between 5.2.0 and 5.2.3 */
-# define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_RAW_FENTRY((char*)#ZN, N, A, 0)
-#else
-/* This causes warnings from GCC >= 4.2 (assigning a string literal to char*).
- * But this seems to be unavoidable without directly assuming knowledge of
- * the structure, which changed between PHP4 and PHP5. */
-# define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A)
-#endif
+/* This indirection is to work around const correctness issues in older PHP.
+ * FIXME: Remove for PHP7? Or might user code be using it? */
+#define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A)
-#ifndef ZEND_FE_END
-# define ZEND_FE_END { NULL, NULL, NULL }
-#endif
-
-#ifndef Z_SET_ISREF_P
-/* For PHP < 5.3 */
-# define Z_SET_ISREF_P(z) (z)->is_ref = 1
-#endif
-#ifndef Z_SET_REFCOUNT_P
-/* For PHP < 5.3 */
-# define Z_SET_REFCOUNT_P(z, rc) (z)->refcount = (rc)
-#endif
-
-#define SWIG_LONG_CONSTANT(N, V) zend_register_long_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
-#define SWIG_DOUBLE_CONSTANT(N, V) zend_register_double_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
-#define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), (char*)(V), strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
+#define SWIG_LONG_CONSTANT(N, V) REGISTER_LONG_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT)
+#define SWIG_DOUBLE_CONSTANT(N, V) REGISTER_DOUBLE_CONSTANT(#N, V, CONST_CS | CONST_PERSISTENT)
+#define SWIG_STRING_CONSTANT(N, V) REGISTER_STRING_CONSTANT(#N, (char*)V, CONST_CS | CONST_PERSISTENT)
#define SWIG_CHAR_CONSTANT(N, V) do {\
- static char swig_char = (V);\
- zend_register_stringl_constant((char*)#N, sizeof(#N), &swig_char, 1, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);\
+ char swig_char = (V);\
+ REGISTER_STRINGL_CONSTANT(#N, &swig_char, 1, CONST_CS | CONST_PERSISTENT);\
} while (0)
-/* These TSRMLS_ stuff should already be defined now, but with older php under
- redhat are not... */
-#ifndef TSRMLS_D
-#define TSRMLS_D
-#endif
-#ifndef TSRMLS_DC
-#define TSRMLS_DC
-#endif
-#ifndef TSRMLS_C
-#define TSRMLS_C
-#endif
-#ifndef TSRMLS_CC
-#define TSRMLS_CC
-#endif
-
#ifdef __cplusplus
}
#endif
-/* But in fact SWIG_ConvertPtr is the native interface for getting typed
- pointer values out of zvals. We need the TSRMLS_ macros for when we
- make PHP type calls later as we handle php resources */
-#define SWIG_ConvertPtr(obj,pp,type,flags) SWIG_ZTS_ConvertPtr(obj,pp,type,flags TSRMLS_CC)
-
-
#define SWIG_fail goto fail
static const char *default_error_msg = "Unknown error occurred";
@@ -93,11 +53,10 @@ typedef struct {
int newobject;
} swig_object_wrapper;
-#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a))
static void
-SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
+SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) {
/*
* First test for Null pointers. Return those as PHP native NULL
*/
@@ -114,19 +73,19 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
value->newobject=(newobject & 1);
if ((newobject & 2) == 0) {
/* Just register the pointer as a resource. */
- ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
+ ZVAL_RES(z, zend_register_resource(value, *(int *)(type->clientdata)));
} else {
/*
* Wrap the resource in an object, the resource will be accessible
* via the "_cPtr" member. This is currently only used by
* directorin typemaps.
*/
- zval *resource;
- zend_class_entry **ce = NULL;
+ zval resource;
+ zend_class_entry *ce = NULL;
const char *type_name = type->name+3; /* +3 so: _p_Foo -> Foo */
size_t type_name_len;
- int result;
const char * p;
+ HashTable * ht;
/* Namespace__Foo -> Foo */
/* FIXME: ugly and goes wrong for classes with __ in their names. */
@@ -135,26 +94,27 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
}
type_name_len = strlen(type_name);
- MAKE_STD_ZVAL(resource);
- ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata));
+ ZVAL_RES(&resource, zend_register_resource(value, *(int *)(type->clientdata)));
if (SWIG_PREFIX_LEN > 0) {
- char * classname = (char*)emalloc(SWIG_PREFIX_LEN + type_name_len + 1);
- strcpy(classname, SWIG_PREFIX);
- strcpy(classname + SWIG_PREFIX_LEN, type_name);
- result = zend_lookup_class(classname, SWIG_PREFIX_LEN + type_name_len, &ce TSRMLS_CC);
- efree(classname);
+ zend_string * classname = zend_string_alloc(SWIG_PREFIX_LEN + type_name_len, 0);
+ memcpy(classname->val, SWIG_PREFIX, SWIG_PREFIX_LEN);
+ memcpy(classname->val + SWIG_PREFIX_LEN, type_name, type_name_len);
+ ce = zend_lookup_class(classname);
+ zend_string_release(classname);
} else {
- result = zend_lookup_class((char *)type_name, type_name_len, &ce TSRMLS_CC);
+ zend_string * classname = zend_string_init(type_name, type_name_len, 0);
+ ce = zend_lookup_class(classname);
+ zend_string_release(classname);
}
- if (result != SUCCESS) {
+ if (ce == NULL) {
/* class does not exist */
- object_init(z);
- } else {
- object_init_ex(z, *ce);
+ ce = zend_standard_class_def;
}
- Z_SET_REFCOUNT_P(z, 1);
- Z_SET_ISREF_P(z);
- zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval*), NULL);
+
+ ALLOC_HASHTABLE(ht);
+ zend_hash_init(ht, 1, NULL, NULL, 0);
+ zend_hash_str_update(ht, "_cPtr", sizeof("_cPtr") - 1, &resource);
+ object_and_properties_init(z, ce, ht);
}
return;
}
@@ -170,11 +130,11 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
instance of a resource of the type id, so we have to pass type_name as well.
The two functions which might call this are:
- SWIG_ZTS_ConvertResourcePtr which gets the type name from the resource
+ SWIG_ConvertResourcePtr which gets the type name from the resource
and the registered zend destructors for which we have one per type each
with the type name hard wired in. */
static void *
-SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty TSRMLS_DC) {
+SWIG_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty) {
swig_cast_info *tc;
void *result = 0;
@@ -201,48 +161,53 @@ SWIG_ZTS_ConvertResourceData(void * p, const char *type_name, swig_type_info *ty
/* This function returns a pointer of type ty by extracting the pointer
and type info from the resource in z. z must be a resource.
If it fails, NULL is returned.
- It uses SWIG_ZTS_ConvertResourceData to do the real work. */
+ It uses SWIG_ConvertResourceData to do the real work. */
static void *
-SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
+SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) {
swig_object_wrapper *value;
void *p;
- int type;
const char *type_name;
- value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
- if (type==-1) return NULL;
+ if (Z_RES_TYPE_P(z) == -1) return NULL;
+ value = (swig_object_wrapper *) Z_RES_VAL_P(z);
if (flags & SWIG_POINTER_DISOWN) {
value->newobject = 0;
}
p = value->ptr;
- type_name=zend_rsrc_list_get_rsrc_type(z->value.lval TSRMLS_CC);
+ type_name=zend_rsrc_list_get_rsrc_type(Z_RES_P(z));
- return SWIG_ZTS_ConvertResourceData(p, type_name, ty TSRMLS_CC);
+ return SWIG_ConvertResourceData(p, type_name, ty);
}
/* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
_cPtr is a resource pointing to the object */
static int
-SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC) {
+SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) {
if (z == NULL) {
*ptr = 0;
return 0;
}
- switch (z->type) {
+ switch (Z_TYPE_P(z)) {
case IS_OBJECT: {
- zval ** _cPtr;
- if (zend_hash_find(HASH_OF(z),(char*)"_cPtr",sizeof("_cPtr"),(void**)&_cPtr)==SUCCESS) {
- if ((*_cPtr)->type==IS_RESOURCE) {
- *ptr = SWIG_ZTS_ConvertResourcePtr(*_cPtr, ty, flags TSRMLS_CC);
- return (*ptr == NULL ? -1 : 0);
- }
+ HashTable * ht = Z_OBJ_HT_P(z)->get_properties(z);
+ if (ht) {
+ zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1);
+ if (_cPtr) {
+ if (Z_TYPE_P(_cPtr) == IS_INDIRECT) {
+ _cPtr = Z_INDIRECT_P(_cPtr);
+ }
+ if (Z_TYPE_P(_cPtr) == IS_RESOURCE) {
+ *ptr = SWIG_ConvertResourcePtr(_cPtr, ty, flags);
+ return (*ptr == NULL ? -1 : 0);
+ }
+ }
}
break;
}
case IS_RESOURCE:
- *ptr = SWIG_ZTS_ConvertResourcePtr(z, ty, flags TSRMLS_CC);
+ *ptr = SWIG_ConvertResourcePtr(z, ty, flags);
return (*ptr == NULL ? -1 : 0);
case IS_NULL:
*ptr = 0;
@@ -254,22 +219,15 @@ SWIG_ZTS_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags TSRMLS_DC
static char const_name[] = "swig_runtime_data_type_pointer";
static swig_module_info *SWIG_Php_GetModule() {
- zval *pointer;
- swig_module_info *ret = 0;
- TSRMLS_FETCH();
-
- MAKE_STD_ZVAL(pointer);
-
- if (zend_get_constant(const_name, sizeof(const_name) - 1, pointer TSRMLS_CC)) {
- if (pointer->type == IS_LONG) {
- ret = (swig_module_info *) pointer->value.lval;
+ zval *pointer = zend_get_constant_str(const_name, sizeof(const_name) - 1);
+ if (pointer) {
+ if (Z_TYPE_P(pointer) == IS_LONG) {
+ return (swig_module_info *) pointer->value.lval;
}
}
- FREE_ZVAL(pointer);
- return ret;
+ return NULL;
}
static void SWIG_Php_SetModule(swig_module_info *pointer) {
- TSRMLS_FETCH();
REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
}
diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i
index aaa5dc9cd..b55751f07 100644
--- a/Lib/php/std_string.i
+++ b/Lib/php/std_string.i
@@ -24,53 +24,68 @@ namespace std {
class string;
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) string, const string& %{
- $1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
+ $1 = (Z_TYPE($input) == IS_STRING) ? 1 : 0;
%}
%typemap(in) string %{
- convert_to_string_ex($input);
- $1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
+ convert_to_string(&$input);
+ $1.assign(Z_STRVAL($input), Z_STRLEN($input));
%}
%typemap(directorout) string %{
- convert_to_string_ex(&$input);
+ if (!EG(exception)) {
+ convert_to_string($input);
$result.assign(Z_STRVAL_P($input), Z_STRLEN_P($input));
+ }
%}
%typemap(out) string %{
- ZVAL_STRINGL($result, const_cast($1.data()), $1.size(), 1);
+ ZVAL_STRINGL($result, $1.data(), $1.size());
%}
%typemap(directorin) string, const string& %{
- ZVAL_STRINGL($input, const_cast($1.data()), $1.size(), 1);
+ ZVAL_STRINGL($input, $1.data(), $1.size());
%}
%typemap(out) const string & %{
- ZVAL_STRINGL($result, const_cast($1->data()), $1->size(), 1);
+ ZVAL_STRINGL($result, $1->data(), $1->size());
%}
%typemap(throws) string, const string& %{
- zend_throw_exception(NULL, const_cast($1.c_str()), 0 TSRMLS_CC);
+ zend_throw_exception(NULL, $1.c_str(), 0);
return;
%}
+ %typemap(in) const string & ($*1_ltype temp) %{
+ convert_to_string(&$input);
+ temp.assign(Z_STRVAL($input), Z_STRLEN($input));
+ $1 = &temp;
+ %}
+
/* These next two handle a function which takes a non-const reference to
* a std::string and modifies the string. */
- %typemap(in) string & ($*1_ltype temp) %{
- convert_to_string_ex($input);
- temp.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
- $1 = &temp;
+ %typemap(in,byref=1) string & ($*1_ltype temp) %{
+ {
+ zval * p = Z_ISREF($input) ? Z_REFVAL($input) : &$input;
+ convert_to_string(p);
+ temp.assign(Z_STRVAL_P(p), Z_STRLEN_P(p));
+ $1 = &temp;
+ }
%}
%typemap(directorout) string & ($*1_ltype *temp) %{
- convert_to_string_ex(&$input);
+ if (!EG(exception)) {
+ convert_to_string($input);
temp = new $*1_ltype(Z_STRVAL_P($input), Z_STRLEN_P($input));
swig_acquire_ownership(temp);
$result = temp;
+ }
%}
%typemap(argout) string & %{
- ZVAL_STRINGL(*($input), const_cast($1->data()), $1->size(), 1);
+ if (Z_ISREF($input)) {
+ ZVAL_STRINGL(Z_REFVAL($input), $1->data(), $1->size());
+ }
%}
/* SWIG will apply the non-const typemap above to const string& without
diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i
index faae0a6ac..c248a588e 100644
--- a/Lib/php/typemaps.i
+++ b/Lib/php/typemaps.i
@@ -27,87 +27,77 @@
%define BOOL_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
- convert_to_boolean_ex($input);
- temp = Z_LVAL_PP($input) ? true : false;
+ convert_to_boolean(&$input);
+ temp = (Z_TYPE($input) == IS_TRUE);
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
- zval *o;
- MAKE_STD_ZVAL(o);
- ZVAL_BOOL(o,temp$argnum);
- t_output_helper( &$result, o TSRMLS_CC );
+ zval o;
+ ZVAL_BOOL(&o, temp$argnum);
+ t_output_helper($result, &o);
}
%typemap(in) TYPE *REFERENCE (TYPE lvalue), TYPE &REFERENCE (TYPE lvalue)
%{
- convert_to_boolean_ex($input);
- lvalue = (*$input)->value.lval ? true : false;
+ convert_to_boolean($input);
+ lvalue = (Z_TYPE_P($input) == IS_TRUE);
$1 = &lvalue;
%}
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
- (*$arg)->value.lval = lvalue$argnum ? true : false;
- (*$arg)->type = IS_BOOL;
+ ZVAL_BOOL(&$arg, lvalue$argnum ? true : false);
%}
%enddef
%define DOUBLE_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
- convert_to_double_ex($input);
- temp = (TYPE) Z_DVAL_PP($input);
+ temp = (TYPE) zval_get_double(&$input);
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
- zval *o;
- MAKE_STD_ZVAL(o);
- ZVAL_DOUBLE(o,temp$argnum);
- t_output_helper( &$result, o TSRMLS_CC );
+ zval o;
+ ZVAL_DOUBLE(&o, temp$argnum);
+ t_output_helper($result, &o);
}
%typemap(in) TYPE *REFERENCE (TYPE dvalue), TYPE &REFERENCE (TYPE dvalue)
%{
- convert_to_double_ex($input);
- dvalue = (TYPE) (*$input)->value.dval;
+ dvalue = (TYPE) zval_get_double(&$input);
$1 = &dvalue;
%}
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
- $1->value.dval = (double)(lvalue$argnum);
- $1->type = IS_DOUBLE;
+ ZVAL_DOUBLE(&$arg, (double)(lvalue$argnum));
%}
%enddef
%define INT_TYPEMAP(TYPE)
%typemap(in) TYPE *INPUT(TYPE temp), TYPE &INPUT(TYPE temp)
%{
- convert_to_long_ex($input);
- temp = (TYPE) Z_LVAL_PP($input);
+ temp = (TYPE) zval_get_long(&$input);
$1 = &temp;
%}
%typemap(argout) TYPE *INPUT, TYPE &INPUT "";
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;";
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{
- zval *o;
- MAKE_STD_ZVAL(o);
- ZVAL_LONG(o,temp$argnum);
- t_output_helper( &$result, o TSRMLS_CC );
+ zval o;
+ ZVAL_LONG(&o, temp$argnum);
+ t_output_helper($result, &o);
}
%typemap(in) TYPE *REFERENCE (TYPE lvalue), TYPE &REFERENCE (TYPE lvalue)
%{
- convert_to_long_ex($input);
- lvalue = (TYPE) (*$input)->value.lval;
+ lvalue = (TYPE) zval_get_long(&$input);
$1 = &lvalue;
%}
%typemap(argout) TYPE *REFERENCE, TYPE &REFERENCE
%{
- (*$arg)->value.lval = (long)(lvalue$argnum);
- (*$arg)->type = IS_LONG;
+ ZVAL_LONG(&$arg, (long)(lvalue$argnum));
%}
%enddef
@@ -128,16 +118,15 @@ INT_TYPEMAP(signed char);
INT_TYPEMAP(long long);
%typemap(argout,fragment="t_output_helper") long long *OUTPUT
{
- zval *o;
- MAKE_STD_ZVAL(o);
+ zval o;
if ((long long)LONG_MIN <= temp$argnum && temp$argnum <= (long long)LONG_MAX) {
- ZVAL_LONG(o, temp$argnum);
+ ZVAL_LONG(&o, (long)temp$argnum);
} else {
char temp[256];
sprintf(temp, "%lld", (long long)temp$argnum);
- ZVAL_STRING(o, temp, 1);
+ ZVAL_STRING(&o, temp);
}
- t_output_helper( &$result, o TSRMLS_CC );
+ t_output_helper($result, &o);
}
%typemap(in) TYPE *REFERENCE (long long lvalue)
%{
@@ -147,38 +136,35 @@ INT_TYPEMAP(long long);
%typemap(argout) long long *REFERENCE
%{
if ((long long)LONG_MIN <= lvalue$argnum && lvalue$argnum <= (long long)LONG_MAX) {
- (*$arg)->value.lval = (long)(lvalue$argnum);
- (*$arg)->type = IS_LONG;
+ ZVAL_LONG(&$arg, (long)temp$argnum);
} else {
char temp[256];
sprintf(temp, "%lld", (long long)lvalue$argnum);
- ZVAL_STRING((*$arg), temp, 1);
+ ZVAL_STRING(&$arg, temp);
}
%}
%typemap(argout) long long &OUTPUT
%{
if ((long long)LONG_MIN <= *arg$argnum && *arg$argnum <= (long long)LONG_MAX) {
- ($result)->value.lval = (long)(*arg$argnum);
- ($result)->type = IS_LONG;
+ ZVAL_LONG($result, (long)(*arg$argnum));
} else {
char temp[256];
sprintf(temp, "%lld", (long long)(*arg$argnum));
- ZVAL_STRING($result, temp, 1);
+ ZVAL_STRING($result, temp);
}
%}
INT_TYPEMAP(unsigned long long);
%typemap(argout,fragment="t_output_helper") unsigned long long *OUTPUT
{
- zval *o;
- MAKE_STD_ZVAL(o);
+ zval o;
if (temp$argnum <= (unsigned long long)LONG_MAX) {
- ZVAL_LONG(o, temp$argnum);
+ ZVAL_LONG(&o, temp$argnum);
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)temp$argnum);
- ZVAL_STRING(o, temp, 1);
+ ZVAL_STRING(&o, temp);
}
- t_output_helper( &$result, o TSRMLS_CC );
+ t_output_helper($result, &o);
}
%typemap(in) TYPE *REFERENCE (unsigned long long lvalue)
%{
@@ -188,23 +174,21 @@ INT_TYPEMAP(unsigned long long);
%typemap(argout) unsigned long long *REFERENCE
%{
if (lvalue$argnum <= (unsigned long long)LONG_MAX) {
- (*$arg)->value.lval = (long)(lvalue$argnum);
- (*$arg)->type = IS_LONG;
+ ZVAL_LONG($arg, (long)(lvalue$argnum));
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)lvalue$argnum);
- ZVAL_STRING((*$arg), temp, 1);
+ ZVAL_STRING((*$arg), temp);
}
%}
%typemap(argout) unsigned long long &OUTPUT
%{
if (*arg$argnum <= (unsigned long long)LONG_MAX) {
- ($result)->value.lval = (long)(*arg$argnum);
- ($result)->type = IS_LONG;
+ ZVAL_LONG($result, (long)(*arg$argnum));
} else {
char temp[256];
sprintf(temp, "%llu", (unsigned long long)(*arg$argnum));
- ZVAL_STRING($result, temp, 1);
+ ZVAL_STRING($result, temp);
}
%}
@@ -270,18 +254,17 @@ INT_TYPEMAP(unsigned long long);
%typemap(in) char INPUT[ANY] ( char temp[$1_dim0] )
%{
- convert_to_string_ex($input);
- strncpy(temp,Z_STRVAL_PP($input),$1_dim0);
+ convert_to_string(&$input);
+ strncpy(temp, Z_STRVAL($input), $1_dim0);
$1 = temp;
%}
%typemap(in,numinputs=0) char OUTPUT[ANY] ( char temp[$1_dim0] )
"$1 = temp;";
%typemap(argout,fragment="t_output_helper") char OUTPUT[ANY]
{
- zval *o;
- MAKE_STD_ZVAL(o);
- ZVAL_STRINGL(o,temp$argnum,$1_dim0);
- t_output_helper( &$result, o TSRMLS_CC );
+ zval o;
+ ZVAL_STRINGL(&o, temp$argnum, $1_dim0);
+ t_output_helper($result, &o);
}
%typemap(in,numinputs=0) void **OUTPUT (int force),
@@ -289,9 +272,9 @@ INT_TYPEMAP(unsigned long long);
%{
/* If they pass NULL by reference, make it into a void*
This bit should go in arginit if arginit support init-ing scripting args */
- if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, 0) < 0) {
+ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0) {
/* So... we didn't get a ref or ptr, but we'll accept NULL by reference */
- if (!((*$input)->type==IS_NULL && PZVAL_IS_REF(*$input))) {
+ if (!(Z_ISREF($input) && Z_ISNULL_P(Z_REFVAL($input)))) {
/* wasn't a pre/ref/thing, OR anything like an int thing */
SWIG_PHP_Error(E_ERROR, "Type error in argument $arg of $symname.");
}
@@ -313,7 +296,7 @@ INT_TYPEMAP(unsigned long long);
void *&OUTPUT
%{
if (force$argnum) { /* pass back arg$argnum through params ($arg) if we can */
- if (!PZVAL_IS_REF(*$arg)) {
+ if (!Z_ISREF($arg)) {
SWIG_PHP_Error(E_WARNING, "Parameter $argnum of $symname wasn't passed by reference");
} else {
SWIG_SetPointerZval(*$arg, (void *) ptr$argnum, $*1_descriptor, 1);
diff --git a/Lib/php/utils.i b/Lib/php/utils.i
index 408a3b366..8581646a2 100644
--- a/Lib/php/utils.i
+++ b/Lib/php/utils.i
@@ -1,70 +1,65 @@
%define CONVERT_BOOL_IN(lvar,t,invar)
- convert_to_boolean_ex(invar);
- lvar = (t) Z_LVAL_PP(invar);
+ lvar = (t) zval_is_true(&invar);
%enddef
%define CONVERT_INT_IN(lvar,t,invar)
- convert_to_long_ex(invar);
- lvar = (t) Z_LVAL_PP(invar);
+ lvar = (t) zval_get_long(&invar);
%enddef
%define CONVERT_LONG_LONG_IN(lvar,t,invar)
- switch ((*(invar))->type) {
+ switch (Z_TYPE(invar)) {
case IS_DOUBLE:
- lvar = (t) (*(invar))->value.dval;
+ lvar = (t) Z_DVAL(invar);
break;
case IS_STRING: {
char * endptr;
errno = 0;
- lvar = (t) strtoll((*(invar))->value.str.val, &endptr, 10);
+ lvar = (t) strtoll(Z_STRVAL(invar), &endptr, 10);
if (*endptr && !errno) break;
/* FALL THRU */
}
default:
- convert_to_long_ex(invar);
- lvar = (t) (*(invar))->value.lval;
+ lvar = (t) zval_get_long(&invar);
}
%enddef
%define CONVERT_UNSIGNED_LONG_LONG_IN(lvar,t,invar)
- switch ((*(invar))->type) {
+ switch (Z_TYPE(invar)) {
case IS_DOUBLE:
- lvar = (t) (*(invar))->value.dval;
+ lvar = (t) Z_DVAL(invar);
break;
case IS_STRING: {
char * endptr;
errno = 0;
- lvar = (t) strtoull((*(invar))->value.str.val, &endptr, 10);
+ lvar = (t) strtoull(Z_STRVAL(invar), &endptr, 10);
if (*endptr && !errno) break;
/* FALL THRU */
}
default:
- convert_to_long_ex(invar);
- lvar = (t) (*(invar))->value.lval;
+ lvar = (t) zval_get_long(&invar);
}
%enddef
%define CONVERT_INT_OUT(lvar,invar)
- lvar = (t) Z_LVAL_PP(invar);
+ lvar = (t) zval_get_long(&invar);
%enddef
%define CONVERT_FLOAT_IN(lvar,t,invar)
- convert_to_double_ex(invar);
- lvar = (t) Z_DVAL_PP(invar);
+ lvar = (t) zval_get_double(&invar);
%enddef
%define CONVERT_CHAR_IN(lvar,t,invar)
- convert_to_string_ex(invar);
- lvar = (t) *Z_STRVAL_PP(invar);
+ convert_to_string(&invar);
+ lvar = (t) Z_STRVAL(invar)[0];
%enddef
%define CONVERT_STRING_IN(lvar,t,invar)
- if ((*invar)->type==IS_NULL) {
+ if (Z_ISNULL(invar)) {
lvar = (t) 0;
} else {
- convert_to_string_ex(invar);
- lvar = (t) Z_STRVAL_PP(invar);
+ convert_to_string(&invar);
+ lvar = (t) Z_STRVAL(invar);
}
%enddef
@@ -80,35 +75,42 @@
%}
%typemap(directorout) TYPE
%{
- CONVERT_IN($result,$1_ltype,&$input);
+ if (!EG(exception)) {
+ CONVERT_IN($result, $1_ltype, *$input);
+ } else {
+ typedef $1_ltype swig_result_typedef;
+ $result = swig_result_typedef();
+ }
%}
%typemap(directorout) const TYPE & ($*1_ltype temp)
%{
- CONVERT_IN(temp,$*1_ltype,&$input);
+ if (!EG(exception)) {
+ CONVERT_IN(temp, $*1_ltype, *$input);
+ } else {
+ typedef $*1_ltype swig_result_typedef;
+ temp = swig_result_typedef();
+ }
$result = &temp;
%}
%enddef
%fragment("t_output_helper","header") %{
static void
-t_output_helper(zval **target, zval *o TSRMLS_DC) {
- zval *tmp;
- if ( (*target)->type == IS_ARRAY ) {
+t_output_helper(zval *target, zval *o) {
+ zval tmp;
+ if (Z_TYPE_P(target) == IS_ARRAY) {
/* it's already an array, just append */
- add_next_index_zval( *target, o );
+ add_next_index_zval(target, o);
return;
}
- if ( (*target)->type == IS_NULL ) {
- REPLACE_ZVAL_VALUE(target,o,1);
- FREE_ZVAL(o);
+ if (Z_TYPE_P(target) == IS_NULL) {
+ /* NULL isn't refcounted */
+ ZVAL_COPY_VALUE(target, o);
return;
}
- ALLOC_INIT_ZVAL(tmp);
- *tmp = **target;
- zval_copy_ctor(tmp);
- array_init(*target);
- add_next_index_zval( *target, tmp);
- add_next_index_zval( *target, o);
-
+ ZVAL_DUP(&tmp, target);
+ array_init(target);
+ add_next_index_zval(target, &tmp);
+ add_next_index_zval(target, o);
}
%}
diff --git a/Lib/php5/const.i b/Lib/php5/const.i
new file mode 100644
index 000000000..061ba99a2
--- /dev/null
+++ b/Lib/php5/const.i
@@ -0,0 +1,51 @@
+/* -----------------------------------------------------------------------------
+ * const.i
+ *
+ * Typemaps for constants
+ * ----------------------------------------------------------------------------- */
+
+%typemap(consttab) int,
+ unsigned int,
+ short,
+ unsigned short,
+ long,
+ unsigned long,
+ unsigned char,
+ signed char,
+ bool,
+ enum SWIGTYPE
+ "SWIG_LONG_CONSTANT($symname, ($1_type)$value);";
+
+%typemap(consttab) float,
+ double
+ "SWIG_DOUBLE_CONSTANT($symname, $value);";
+
+%typemap(consttab) char
+ "SWIG_CHAR_CONSTANT($symname, $value);";
+
+%typemap(consttab) char *,
+ const char *,
+ char [],
+ const char []
+ "SWIG_STRING_CONSTANT($symname, $value);";
+
+%typemap(consttab) SWIGTYPE *,
+ SWIGTYPE &,
+ SWIGTYPE &&,
+ SWIGTYPE [] {
+ zval *z_var;
+ zend_constant c;
+ size_t len = sizeof("$symname") - 1;
+ MAKE_STD_ZVAL(z_var);
+ SWIG_SetPointerZval(z_var, (void*)$value, $1_descriptor, 0);
+ c.value = *z_var;
+ zval_copy_ctor(&c.value);
+ c.name = zend_strndup("$symname", len);
+ c.name_len = len+1;
+ c.flags = CONST_CS | CONST_PERSISTENT;
+ c.module_number = module_number;
+ zend_register_constant( &c TSRMLS_CC );
+}
+
+/* Handled as a global variable. */
+%typemap(consttab) SWIGTYPE (CLASS::*) "";
diff --git a/Lib/php5/director.swg b/Lib/php5/director.swg
new file mode 100644
index 000000000..638a1697d
--- /dev/null
+++ b/Lib/php5/director.swg
@@ -0,0 +1,170 @@
+/* -----------------------------------------------------------------------------
+ * director.swg
+ *
+ * This file contains support for director classes so that PHP proxy
+ * methods can be called from C++.
+ * ----------------------------------------------------------------------------- */
+
+#ifndef SWIG_DIRECTOR_PHP_HEADER_
+#define SWIG_DIRECTOR_PHP_HEADER_
+
+#include
+#include
+#include