newInstanceArgs does not work for classes without constructors

Bug #52854 ReflectionClass::newInstanceArgs does not work for classes without constructors
Submitted: 2010-09-15 14:40 UTC Modified: 2010-11-21 13:24 UTC
From: mail_ben_schmidt at yahoo dot com dot au Assigned: johannes (profile)
Status: Closed Package: Class/Object related
PHP Version: 5.3.3 OS: Mac OS X 10.6.2
Private report: No CVE-ID: None

 [2010-09-15 14:40 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports

 [2010-09-15 18:03 UTC] johannes@php.net

-Status: Open +Status: Assigned -Assigned To: +Assigned To: johannes