php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
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

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-15 18:03 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: johannes
 [2010-11-21 13:24 UTC] johannes@php.net
Automatic comment from SVN on behalf of johannes
Revision: http://svn.php.net/viewvc/?view=revision&revision=305605
Log: - Fix #52854 (ReflectionClass::newInstanceArgs does not work for classes without constructors
 [2010-11-21 13:24 UTC] johannes@php.net
-Status: Assigned +Status: Closed
 [2010-11-21 13:24 UTC] johannes@php.net
Fixed for 5.3.4 and trunk.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC