[TYPO3-dev] Extending classes on demand

Franz Holzinger franz at fholzinger.com
Mon Aug 28 23:31:07 CEST 2006


Johannes Reichardt a écrit :
> Hi there,
> 
> i have a few questions regarding php, classes, extending and that 
> related to typo3 also.
> 
> Right now i struggle with a construction like this:
> 
> class tx_xy {
>    function foo() {
>        require_once('class.tx_xy_extended.php');
>        return $this->foo_extended();
>    }
> }
> in seperate file:
> 
> class tx_xy_extended extends tx_xy {
>    function foo_extended() {
>       return 'damn oop shit';
>    }
> }
> 
> echo tx_xy::foo();
> 
> this does not work for many reasons - the most annyoing problem is the 
> problem that the $this-> thing doesnt work as expected.


This will never work with $this because you did not instantiate any object.

> tx_xy::foo();

return tx_xy_extended::foo_extended();


or with objects:

$obj = t3lib_div::makeInstance('tx_xy');
echo $obj->foo();


  class tx_xy {
     function foo() {
         require_once('class.tx_xy_extended.php');
	$obj = &t3lib_div::getUserObj('tx_xy_extended');
         return $obj->foo_extended();
     }

  }



- Franz




More information about the TYPO3-dev mailing list