[TYPO3-seminars] XCLASS the registrationmanager

Oliver Klee typo3-german-02 at oliverklee.de
Wed Oct 6 23:26:49 CEST 2010


Hi Malte,

Am 05.10.2010 15:44, schrieb Malte Koitka:
> thanks for the fast response. Changing the visibility from private to
> protected was a valuable (also somekind of irritating ) hint. But
> additionally I had to edit the "getInstance" method in the original
> class file, because it always was returning the original instance. Now
> "self::$instance" gets the object of
> "ux_tx_seminars_registrationmanager()" and everything seems fine.
> 
> Do you see any way to implement that the clean way?

Yes, the "new" needs to be changed to a t3lib_div::makeInstance or
tx_oelib_ObjectFactory::make call. The latter is the way recommended for
my projects.

Could you put these two changes in a patch and put it in the bug tracker?

> One additional annotation: Redefining a private method in a subclass
> worked for me some time ago, so I made a simple test.
> 
> class basis {
> 
>     private function test() {
> 
>         echo "Basistest";
>     }
> }
> 
> class ext extends basis {
> 
>     public function test() {
> 
>         echo "Exttest";
>     }
> }
> 
> 
> $obj = new ext();
> $obj->test();

That's because you're calling from the outside. If you're calling from
the inside, PHP uses static binding for private methods AFAIK.

As this is extremely confusing (almost as much as the binding of member
variables in Java - I still often mix it up), I strongly recommend to
*never* override private methods or members in PHP.


Oli
-- 
Certified TYPO3 Integrator | TYPO3 Security Team Member


More information about the TYPO3-project-seminars mailing list