[TYPO3-core] RFC: #15083: Add sectionmark for the hook in t3lib_pageSelect_getPageHook

Dmitry Dulepov dmitry at typo3.org
Wed Jul 14 09:57:34 CEST 2010


Hi!

Georg Ringer wrote:
> Sorry you are right. Does this mean that there is no chance to extend a
> hook forever?

You can add another interface with the same method name but with extra
parameters. Than in the code you check that the class implements one of
them. If it does, you call the method with all parameters. PHP does not
care if you pass extra parameters to functions.

> Adding a configuration array would be IMO the best as this would allow
> to add additional settings later?

I think it is a two sided solution. The advantage of the array is that you
can define any keys. The disadvantage is that you can make mistakes with
keys.  I would prefer to have a configuration class instead. You can't do
the same mistakes with a class that has attributes protected and
getters/setters for them. You would pass this class to the hook and the
hook can use methods of this class to get/set data. Since objects in PHP
are always passed by reference, you can use this class to provide and
receive information.

Using class has extra advantages:
- you keep hook parameter list short
- you can extend the class with extra getters/setters without changing
interfaces

A little problem appears if the hook tries to use a getter or a setter that
does not exist. This can be solved with magic methods (set nothing, return
null, or thrown an exception, which is ideologically correct but from
practical point of view).

-- 
Dmitry Dulepov
TYPO3 core&security teams member
Twitter: http://twitter.com/dmitryd
Read more @ http://dmitry-dulepov.com/


More information about the TYPO3-team-core mailing list