Bug #52854 [Opn->Asn]: ReflectionClass::newInstanceArgs does not work for classes without constructors
Edit report at http://bugs.php.net/bug.php?id=52854&edit=1
ID: 52854
Updated by: johannes@php.net
Reported by: mail_ben_schmidt at yahoo dot com dot au
Summary: ReflectionClass::newInstanceArgs does not work for
classes without constructors
-Status: Open
+Status: Assigned
Type: Bug
Package: Class/Object related
Operating System: Mac OS X 10.6.2
PHP Version: 5.3.3
-Assigned To:
+Assigned To: johannes
Block user comment: N
Previous Comments:
------------------------------------------------------------------------
[2010-09-15 14:40:33] mail_ben_schmidt at yahoo dot com dot au
Description:
------------
ReflectionClass::newInstanceArgs does not work for classes without
constructors when passed an empty array.
This is a duplicate of bug #49376 which has been marked as bogus.
IMHO, it is not bogus, nor is it a documentation problem.
An empty array semantically means no arguments are to be passed. It is
like the distinction between new Test and new Test(). One has no
argument list, and one has an empty argument list, but both work.
Likewise newInstanceArgs(array()) should work equally to
newInstanceArgs(). It is also ridiculous to give an error which says
"you cannot pass any constructor arguments" when you are not, in fact,
attempting to pass any constructor arguments.
Test script:
---------------
class Test {
}
$c = new ReflectionClass('Test');
$t = new Test;
$t = new Test();
$t = $c->newInstance();
$t = $c->newInstanceArgs(array());
Expected result:
----------------
All four constructions should complete without error.
Actual result:
--------------
"ReflectionException: Class Test does not have a constructor, so you
cannot pass any constructor arguments." referring to the line where
newInstanceArgs is called.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52854&edit=1
Thread (3 messages)