diff -Nur Examples/php/callback.orig/example.php Examples/php/callback/example.php --- Examples/php/callback.orig/example.php 2009-06-17 12:03:17.000000000 +0200 +++ Examples/php/callback/example.php 2009-06-17 18:01:32.000000000 +0200 @@ -42,8 +42,13 @@ Callback_run($this->_cPtr); } - function __construct() { - $this->_cPtr=new_Callback(); + function __construct() { + if (get_class($this) === "Callback") { + $_this = null; + } else { + $_this = $this; + } + $this->_cPtr=new_Callback($_this); } } diff -Nur Examples/php/callback.orig/example_wrap.cxx Examples/php/callback/example_wrap.cxx --- Examples/php/callback.orig/example_wrap.cxx 2009-06-17 12:03:17.000000000 +0200 +++ Examples/php/callback/example_wrap.cxx 2009-06-17 18:18:47.000000000 +0200 @@ -1063,6 +1063,37 @@ # define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); } #endif +namespace Swig { + class Director { + public: + zval *swig_self; + Director(zval* self) : swig_self(self) { + } + }; +} + +#include "example_wrap.h" + +SwigDirector_Callback::SwigDirector_Callback(zval *self): Callback(), Swig::Director(self) { +} + +SwigDirector_Callback::~SwigDirector_Callback() { +} + +void SwigDirector_Callback::run() { + if (!swig_self) { + SWIG_PHP_Error(E_ERROR, "this pointer is NULL"); + } + zval retval, funcname; + + ZVAL_STRING(&funcname, (char *)"run", 0); + + call_user_function(EG(function_table), &swig_self, &funcname, + &retval, 0, NULL TSRMLS_CC); + return; +fail: + zend_error(SWIG_ErrorCode(),"%s",SWIG_ErrorMsg()); +} #include @@ -1137,14 +1168,23 @@ ZEND_NAMED_FUNCTION(_wrap_new_Callback) { + zval *arg1; + zval **args[1]; Callback *result = 0 ; SWIG_ResetError(); - if(ZEND_NUM_ARGS() != 0) { + if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) { WRONG_PARAM_COUNT; } - - result = (Callback *)new Callback(); + + arg1 = *args[0]; + + if ( arg1->type != IS_NULL ) { + /* subclassed */ + result = (Callback *)new SwigDirector_Callback(arg1); + } else { + result = (Callback *)new Callback(); + } SWIG_SetPointerZval(return_value, (void *)result, SWIGTYPE_p_Callback, 1); diff -Nur Examples/php/callback.orig/example_wrap.h Examples/php/callback/example_wrap.h --- Examples/php/callback.orig/example_wrap.h 1970-01-01 01:00:00.000000000 +0100 +++ Examples/php/callback/example_wrap.h 2009-06-17 18:17:42.000000000 +0200 @@ -0,0 +1,11 @@ +#ifndef SWIG_example_WRAP_H_ +#define SWIG_example_WRAP_H_ + +class SwigDirector_Callback : public Callback, public Swig::Director { + public: + SwigDirector_Callback(zval *self); + virtual ~SwigDirector_Callback(); + virtual void run(); +}; + +#endif