[TYPO3-dev] Extending classes on demand
Johannes Reichardt
typo3 at gramba.de
Tue Aug 29 02:39:17 CEST 2006
Hi Franz,
thanx for the answer. Somehow classes in php still really confuse me and
i am far away from really understanding i think.
So the "normal" class that is used in typo3 is instantiated already by
typo3 while execution? that is why $this works? is $this right? :)
the problem i have is that the scope is always changing and i do not see
a convinient way to "inline-extend" a class without problems. it would
be just very comfortable to have constructs like this:
class foo {
require_once('class.extends_foo.php');
}
// other php file
extends( {
.../blaaa
}
and in both of them you can access everything like it was one - only
that you load the extends stuff on demand. but i guess i am thinking in
the wrong direction, on the other hand i do not understand why this
won´t work. i would get rid of scope and variable problems quickly...
hrmpf ;)
I am currently trying to understand this interesting seeming article
about "flexible objects" - maybe that will bring me further ;)
http://www-128.ibm.com/developerworks/opensource/library/os-php-flexobj/
- Johannes
> 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
> _______________________________________________
> TYPO3-dev mailing list
> TYPO3-dev at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-dev
>
>
More information about the TYPO3-dev
mailing list