[TYPO3-dev] XCLASS conflict examples

Michael Scharkow mscharkow at gmx.net
Sun Feb 12 15:05:55 CET 2006


Bernhard Kraft wrote:
> 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.

As PHP has no function decorators except public/private/protected, you 
have to work around the fact that you don't want all methods to be 
callable by $cmd. method_exists() does not help here.

And of course, I could use references to the actual methods instead of 
strings in the array, but I prefer the above syntax as it has less ugly 
$%& ;)

And whitelisting seems to be preferable here to blacklisting the 
non-public methods. One could mess with custom function names, so 
__view() is hidden and view() is not, but I prefer explicit over implicit.

> 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) */ );

Right. I was thinking about the filtered array lookup which uses an index.

> 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 :)

Are you doing this at runtime or by preparing the modified files when 
installing stuff? However, using self-modifying code is somewhat 
cheating but I agree that it does work ;)

>> 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* :(

<rant>
I know, I run against these limitations all the time. I guess if you're 
used to really dynamic languages PHP is very annoying. I have recently 
tried to write a class that casts to a string, like

$myform = new t3_form($bla);
return '<div>'.$myform.'</div>;

Although __toString() exists, it only works for print and echo 
statements, how very useful...
</rant>

> 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 ....

Yes, thanks.

Greetings,
Michael




More information about the TYPO3-dev mailing list