#44604 [Opn]: newInstanceArgs (ReflectionClass) and visivility
ID: 44604
Updated by: jani@php.net
Reported By: vituko at gmail dot com
Status: Open
-Bug Type: Scripting Engine problem
+Bug Type: Feature/Change Request
Operating System: Debian GNU/Linux
PHP Version: 5.3CVS-2008-04-02 (CVS)
Assigned To: fb-req-jani
New Comment:
Reclassified. NOTE: Discussion about this should be done on the
internals mailing list..
Previous Comments:
------------------------------------------------------------------------
[2008-04-04 14:06:57] vituko at gmail dot com
I didn't say it was a bug.
I only said that it is a limitation... maybe easy to change.
ReflectionClass -> newInstanceArgs is very nice but only works with
public constructors. If a class constructor is private, for example, you
cannot instantiate it with this method, even from this class scope.
The same example with call_user_func_array, you change the constructor
with another method and it works... But this function doesn't allow to
instantiate an object (you can only call a parent constructor on an
already instantiated object).
So, in this context (a class with a private/protected constructor), the
only way of instantiating it with an arbitrary number of arguments is to
build a string and use eval... not very nice nor performant.
Thanks
------------------------------------------------------------------------
[2008-04-03 11:23:41] jani@php.net
And the bug here is...?
------------------------------------------------------------------------
[2008-04-02 08:14:56] vituko at gmail dot com
Description:
------------
1 - call_user_func_array ($ref_f, $taboa) ;
Here, the visibility is computed from the context where this
function is called.
2 - $obx -> newInstanceArgs ($taboa) ;
ReflectionException : Access to non-public constructor of class ...
Constructor must be public anyway.
So ... eval is not so bad.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44604&edit=1
Thread (8 messages)