[TYPO3-core] RFC: #15822: t3lib_beFunc use $this in static methods

Steffen Kamper info at sk-typo3.de
Mon Sep 27 12:29:40 CEST 2010


Hi Dmitry,

Dmitry Dulepov schrieb:
> Hi!
> 
> Steffen Kamper wrote:
>> One time some methods inside t3lib_beFunc were changed to static
>> functions. But they call other functions using $this which is not
>> available in static context.
>> Use NULL for the reference.
> 
> There can be side effects. In case if the function is not defined as static
> but called statically, $this exists and points to a first object instance
> on the stack. The hook can use that to get the instance of the calling
> class (TCEforms or List instance, for example). Setting it to null may
> break that. Such assumptions of having $this are hacky, of course, but we
> may provide better compatibility by adding an optional parameter to such
> functions that is null by default. We could pass that as $this to hooks.
> That would ensure the same behavior. Also other core functions should be
> modified to provide their $this to t3lib_BEfunc static functions.
>

i thought of the consequence of passing NULL to userFunc as it's called 
there, if someone use the ref in the hook and use it like 
$ref::someMethod or $ref->someMethod. but these functions are called 
inside the core statically, so $ref doesn't exists.

> I do not know if anybody uses $this in such hooks, so I am not sure if we
> should provide such compatibility layer.
> 

I'm not sure how to do it better. Maybe there shoud be an object like
$reference = t3lib_div::makeInstance't3lib_BEfunc')
for passing?

vg Steffen


More information about the TYPO3-team-core mailing list