#44604 [Fbk->Opn]: newInstanceArgs (ReflectionClass) and visivility

From: Date: Fri, 04 Apr 2008 14:06:57 +0000
Subject: #44604 [Fbk->Opn]: newInstanceArgs (ReflectionClass) and visivility
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-123963@lists.php.net to get a copy of this message
 ID:               44604
 User updated by:  vituko at gmail dot com
 Reported By:      vituko at gmail dot com
-Status:           Feedback
+Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Debian GNU/Linux
 PHP Version:      5.3CVS-2008-04-02 (CVS)
 Assigned To:      fb-req-jani
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

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

« previous php.bugs (#123963) next »