<?php 
require 'src/object-ext.php'; 
 
class CTest extends CExtendable 
{ 
    public function testing() 
    { 
        $aArgs = func_get_args(); 
        echo "CTest::testing() was called.  Arguments:<br/>"; 
        echo '<pre>' . print_r($aArgs, TRUE) . '</pre>'; 
    } 
} 
 
class CAnotherTest implements IExtendableChild 
{ 
    protected $_oParent; 
     
    public function extendedFunction() 
    { 
        $aArgs = func_get_args(); 
        echo "CAnotherTest::extendedFunction() was called.  Arguments:<br/>"; 
        echo '<pre>' . print_r($aArgs, TRUE) . '</pre>'; 
         
        // call parent! 
        $this->_oParent->testing('Called from extended class.'); 
    } 
     
    // IExtendableChild 
    public function _setParent(CExtendable $oParent) 
    { 
        $this->_oParent = $oParent; 
    } 
} 
 
function testing(_OP $o) 
{ 
    $o->_check(OP(array( 
        'test' => 'string', 
        'callback' => 'ICallback', 
        'object' => 'CTest', 
    ))); 
     
    // call callback 
    $o->callback('This is another argument!'); 
     
    // call object method 
    $o->object->testing('Just one argument here.'); 
} 
 
$test = new CTest(); 
 
testing(OP(array( 
    'test' => 'This is a test', 
    'callback' => $test->_callback()->testing('This is an argument'), 
    'object' => $test, 
))); 
 
// extend 
$test->_extend(new CAnotherTest()); 
$test->extendedFunction('This function is extended.'); 
 
// test object 
$object = OP(array( 
    'int' => 1, 
    'string' => 'testing', 
)); 
 
// testing 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
echo ($object->string .= $object->int++) . '<br/>'; 
?>
 
 |