function mycheck($person, $expected) { $debug = 0; # Normal target language polymorphic call $ret = $person->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"; } }
require "example.php"; # Class, which overwrites Callback::run(). class PhpCallback extends Callback { function run() { print "PhpCallback.run()\n"; } } # Create an Caller instance $caller = new Caller(); # Add a simple C++ callback (caller owns the callback, so # we disown it first by clearing the .thisown flag). print "Adding and calling a normal C++ callback\n"; print "----------------------------------------\n"; $callback = new Callback(); $callback->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";