Intercepting Method Calls with the __call() Method (PHP 5 Only) : __call « Class « PHP






Intercepting Method Calls with the __call() Method (PHP 5 Only)

 
<?php

function r( $item_array, $immediately=false ) {
  return "Registering<br />\n";
}
class Item {
  public $name = "item";
  public $price = 0;

  function __call( $method, $args ) {
    $bloggsfuncs = array ( "r");
    if ( in_array( $method, $bloggsfuncs ) ) {
      array_unshift( $args, get_object_vars( $this ) );
      return call_user_func( $method, $args );
    }
  }
}

$item = new Item();
print $item->r( true );
?>
  
  








Related examples in the same category

1.__call( ) method is called if PHP fails to find the method
2.Using the __call() Method