views:

28

answers:

1

Alright, I may just need a terminology update, but I have been playing in Magento and Joomla, and they do references like

$mage = new Mage;
$mage->block('blockname');

where class Mage through some process I am failing to figure out is calling:

class blockname extends something{

}

Don't quote me on that code, however I am looking to do something like that where I have a file that I can do $myscript->block('blockname'); and it will load and call the file with class blockname.

I hope that is not too confusing, but any help is appreciated.

Thanks in advance!

+3  A: 
class Mage {
    private $block;

    public function block($blockname) {
        if (!class_exists($blockname, true)) {
            throw new InvalidArgumentException("Not a valid class name: $blockname");
        }
        $this->block = new $blockname;
    }
}

The loading of the class definition (if not already done) is typically accomplished through autoloading (see here).

Artefacto
Ah, I did not know you could do "new $varible". Thanks!
Nitroware