PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Andrew Hanna   Object Extensions for PHP   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Sample Usage
Class: Object Extensions for PHP
Extend objects with more functions and variables
Author: By
Last change:
Date: 18 years ago
Size: 1,948 bytes
 

Contents

Class file image Download
<?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/>';
?>