[Typo3-dev] Library manager instead of globals
Martin T. Kutschker
Martin.T.Kutschker at blackbox.net
Tue Mar 16 15:40:40 CET 2004
René Fritz wrote:
>
>
> $myObject = t3lib_div::makeInstanceService('ServiceType or ServiceKey');
As far as I read the code in RC1 you can use only the type. But you can
disallow (!) service implementations explicetly by naming their keys as
an extra paramater.
> BTW: I have a problem with services related to the fact that php4 have no real
> destructors. All my tests with
>
> register_shutdown_function(array(&$this, '__destruct'));
>
> did not work, because the function seems to make a copy of the object and
> don't take the reference. Therefore the data of the object is - while
> destruction - not the same like the 'real' object.
>
> I made many tests and added & to makeInstance() to return a reference but
> nothing works.
I guess you read all those nice comments on
http://www.php.net/manual/en/function.register-shutdown-function.php ?
BTW in RC3.6 makeInstanceService() doesn't use a & before the function
name. A comment asks "objects are passed always as reference - right?"
The answer is no. Objects are always copied in 4.x unless you specfiy
it. The function and the assignement need a &. Though in 5.0 this has
been changed someway or other.
So you'd need a $obj =& t3lib_div::makeInstance($info['className']); as
well.
Masi
PS: I changed once all occurences of "$obj = t3lib_div::makeInstance()"
into "$obj =& t3lib_div::makeInstance()". Made makeInstance return a ref
by adding a & and it worked out allright for 3.5. The only thing that
broke was the extension manager or something else that had a weird class
loading mechanism that worked via globals.
I can find the file in question if anyone is interested.
More information about the TYPO3-dev
mailing list