[TYPO3-dev] XCLASS conflict examples

Bernhard Kraft kraftb at kraftb.at
Sun Feb 12 14:43:37 CET 2006


Michael Scharkow wrote:

>     $this->register = array('index','singleview','latest','search');

You can register a method in an array, you could use method_exists and there
are surely other nice ways.

> Actually, the overhead is minimal because (ignoring filters) you only 
> lookup a dictionary key (in $this->register) and do a cheap 
> method_exists call. So it scales O(1).

This would have to get evaluated with a "microtime()" measuring script.

I don't think that an PHP array key lookup scales O(1). No list lookup scales O(1)
(Most probably PHP array keys are binary trees O(log(n)) or hash tables O(?)).
Except the list index (always 0..(count($a)-1)) which is a lookup table - if
you mean this one I must have missed something. What I get from your code is
that you use "in_array" and this one is fore sure not O(1).
http://www.cprogramming.com/tutorial/computersciencetheory/algorithmicefficiency3.html

O(1) would be the lookup of an index in a static array (which PHP arrays are not of
course) like it can be done in C:
int intArr[5] = {1, 2, 3, 4, 5};

printf("%d\n", intArr[3] /* <= O(1) */ );

> A comparable switch statement will probably not be much faster.

Of course.

> The above *is* practically also using hooks internally.

As I wrote decorator patterns are very similar to hooks except that hooks sometimes
have differnt arguments or already processed ones which is not mentioned in a
"traditional" decorator pattern document (there you always call the concerned methods
of the extending classes and if none exists (or you get to the last one) you call the
method of the base class using the parent:: operator (or you could also have the base
class also in the object-array)))

> However, for the XCLASS problem the difficulty remains to create 
> cascading subclassing, so
> 
> foo extends bar
> foo2 extends bar, but should really extend foo
> etc.
> 
> We basically need a class merge (or mixins) which is impossible with PHP 
> except using eval() which is not an option.

If you don't have get it or didn't look at my screenshots:
What my extension does it exactly this what you wrote that it is difficult and
not possible with PHP :)

It creates the chain of cascaded subclasses ... By modifing the ext_localconf.php
and the respective XCLASS files of the extension (ux_blabal becomes ux_ux_blabla :)

> One possible hook-like way would be to not subclass a real class but an 
> alias that is filled by TYPO3:
> 
> class my_news extends $latest_tt_news_class {
> }

That DOES not work ... I tried it with all possible tricks ...
class my_test extends eval($name) {
define('class_name', 'tx_myclass');
class class_name extends baseclass {

none of them works :(
PHP really su* :(

> However, this is fairly complex and much harder to implement than a 
> simple hook that only modifies some local variable.

If you want to try this XCLASS Manager (which I call it) I could send you a T3X.

Also all others who would like to get a T3X of this are invited to mail me ....


greets,
Bernhard




More information about the TYPO3-dev mailing list