Welcome Guest, Not a member yet? Register   Sign In
Assigning new methods to Loader class from another library
#1

[eluser]zdknudsen[/eluser]
Hi guys,

Is it possible to assign a new method to the Loader library from another library?
Code:
$ci = &get;_instance();
$ci->load->some_method = &$this->some_method
This example obviously doesn't work, but that's what I had in mind.
#2

[eluser]zdknudsen[/eluser]
I found a solution, but I don't like it. Is this really the easiest way?
Code:
class Some_library
{

    function Some_library()
    {
        $ci = &get;_instance();
        $eval = '
class Placeholder extends ' . get_class($ci->load) . ' {
    function some_method()
    {
        $args = func_get_args();
        call_user_func_array(array("Some_library", "load"), $args);
    }
}';
        eval($eval);
        $ci->load = new Placeholder();
    }

    function load($argument1)
    {
        echo $argument1;
    }
}

If someone could show me a cleaner way of doing this I'd be delighted.




Theme © iAndrew 2016 - Forum software by © MyBB