Mega Code Archive

 
Categories / Php / Class
 

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 ); ?>