Olly Betts - 2013-12-16

Sigh, sourceforge just threw away my comment.

It helps a lot if you can supply a complete example - yours is missing the C++ source file corresponding to the virt.h, and the PHP code is incomplete (it doesn't load the module). Also, it helps to say how you're invoking SWIG.

Guessing to fill in the blanks, the first problem I see is you need to call demo::create_concrete():

 $d = demo::create_concrete();
 $d->foo();

The create_concrete you're calling is a flat function wrapper layer underneath the PHP5 class wrappers, which you generally don't want to be calling unless you're doing something tricky. Ideally the flat functions would be called something less likely to be accidentally called, but the flat functions existed before the class wrappers, so we've resisted changing the names to avoid breaking anyone who was already using them. But that was some time ago, and I suspect almost everyone's just using the class wrappers now, so I'm tempted to finally make that change for SWIG 3.0 (due fairly soon).

Also, note that the PHP side can't know the type of the C++ object beyond that it is either base or a subclass of base (how could it?) so _p_base for the resource type is as expected.

Fixing that, base::foo() gets called on the C++ side, because the wrapper code misidentifies this as an upcall. For python, SWIG uses a different approach (details were in my original comment, but it's not important really), and adapting that to PHP gives the desired result here, but I need to try changing SWIG to generate that instead, and then see if it works with the testsuite.

 
Last edit: Olly Betts 2013-12-16