note 86622 added to language.oop5.magic
| From: | patricknegri at gmail dot com | Date: | Sun, 26 Oct 2008 23:57:31 +0000 |
| Subject: | note 86622 added to language.oop5.magic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145785@lists.php.net to get a copy of this message | ||
Imports Pattern - Extend Classes in Real Time:
class BaseClass
{
var $__imported;
var $__imported_functions;
function __construct()
{
$__imported = Array();
$__imported_functions = Array();
}
function Imports($object)
{
$new_imports = new $object();
$imports_name = get_class($new_imports);
array_push( $__imported, Array($imports_name,$new_imports) );
$imports_function = get_class_methods($new_imports);
foreach ($imports_function as $i=>$function_name)
{
$this->__imported_functions[$function_name] = &$new_imports;
}
}
function __call($m, $a)
{
if (array_key_exists($m,$this->__imported_functions))
{
return call_user_func_array(Array($this->__imported_functions[$m],$m),$a);
}
throw new ErrorException ('Call to Undefined Method/Class Function', 0, E_ERROR);
}
}
class ExternalFunc
{
function TestB()
{
echo "External Imported!";
}
}
class B extends BaseClass
{
function __construct()
{
$this->Imports("ExternalFunc");
}
function Msg()
{
echo "Hello world<br />";
}
}
$b = new B();
$b->Msg();
// or call $b->Imports("ExternalFunc");
$b->TestB();
//$b->TestB(1,3,4);
----
Server IP: 69.147.83.197
Probable Submitter: 201.2.24.118
----
Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php
Edit -- https://master.php.net/note/edit/86622
Del: integrated -- https://master.php.net/note/delete/86622/integrated
Del: useless -- https://master.php.net/note/delete/86622/useless
Del: bad code -- https://master.php.net/note/delete/86622/bad+code
Del: spam -- https://master.php.net/note/delete/86622/spam
Del: non-english -- https://master.php.net/note/delete/86622/non-english
Del: in docs -- https://master.php.net/note/delete/86622/in+docs
Del: other reasons-- https://master.php.net/note/delete/86622
Reject -- https://master.php.net/note/reject/86622
Search -- https://master.php.net/manage/user-notes.php