johannes                                 Sun, 21 Nov 2010 12:24:09 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=305605

Log:
- Fix #52854 (ReflectionClass::newInstanceArgs does not work for classes 
without constructors

Bug: http://bugs.php.net/52854 (Assigned) ReflectionClass::newInstanceArgs does 
not work for classes without constructors
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
    A   php/php-src/branches/PHP_5_3/ext/reflection/tests/bug52854.phpt
    U   php/php-src/trunk/ext/reflection/php_reflection.c
    A   php/php-src/trunk/ext/reflection/tests/bug52854.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-11-21 11:58:00 UTC (rev 305604)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-11-21 12:24:09 UTC (rev 305605)
@@ -10,6 +10,8 @@
 - Fixed bug #53366 (Reflection doesnt get dynamic property value from
   getProperty()). (Felipe)
 - Fixed bug #53362 (Segmentation fault when extending SplFixedArray). (Felipe)
+- Fixed bug #52854 (ReflectionClass::newInstanceArgs does not work for classes
+  without constructors). (Johannes)
 - Fixed bug #50987 (unaligned memory access in phar.c).
   (geissert at debian dot org, Ilia)
 - Fixed bug #47168 (printf of floating point variable prints maximum of 40

Modified: php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c        
2010-11-21 11:58:00 UTC (rev 305604)
+++ php/php-src/branches/PHP_5_3/ext/reflection/php_reflection.c        
2010-11-21 12:24:09 UTC (rev 305605)
@@ -4013,7 +4013,7 @@
                if (params) {
                        efree(params);
                }
-       } else if (!ZEND_NUM_ARGS()) {
+       } else if (!ZEND_NUM_ARGS() || !argc) {
                object_init_ex(return_value, ce);
        } else {
                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
"Class %s does not have a constructor, so you cannot pass any constructor 
arguments", ce->name);

Added: php/php-src/branches/PHP_5_3/ext/reflection/tests/bug52854.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/reflection/tests/bug52854.phpt             
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/reflection/tests/bug52854.phpt     
2010-11-21 12:24:09 UTC (rev 305605)
@@ -0,0 +1,28 @@
+--TEST--
+Bug #52854: ReflectionClass::newInstanceArgs does not work for classes without 
constructors
+--FILE--
+<?php
+class Test {
+}
+$c = new ReflectionClass('Test');
+var_dump(new Test);
+var_dump(new Test());
+var_dump($c->newInstance());
+var_dump($c->newInstanceArgs(array()));
+
+try {
+       var_dump($c->newInstanceArgs(array(1)));
+} catch(ReflectionException $e) {
+       echo $e->getMessage()."\n";
+}
+?>
+--EXPECTF--
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+Class Test does not have a constructor, so you cannot pass any constructor 
arguments


Property changes on: 
php/php-src/branches/PHP_5_3/ext/reflection/tests/bug52854.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

Modified: php/php-src/trunk/ext/reflection/php_reflection.c
===================================================================
--- php/php-src/trunk/ext/reflection/php_reflection.c   2010-11-21 11:58:00 UTC 
(rev 305604)
+++ php/php-src/trunk/ext/reflection/php_reflection.c   2010-11-21 12:24:09 UTC 
(rev 305605)
@@ -4296,7 +4296,7 @@
                if (params) {
                        efree(params);
                }
-       } else if (!ZEND_NUM_ARGS()) {
+       } else if (!ZEND_NUM_ARGS() || !argc) {
                object_init_ex(return_value, ce);
        } else {
                zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, 
"Class %s does not have a constructor, so you cannot pass any constructor 
arguments", ce->name);

Added: php/php-src/trunk/ext/reflection/tests/bug52854.phpt
===================================================================
--- php/php-src/trunk/ext/reflection/tests/bug52854.phpt                        
        (rev 0)
+++ php/php-src/trunk/ext/reflection/tests/bug52854.phpt        2010-11-21 
12:24:09 UTC (rev 305605)
@@ -0,0 +1,28 @@
+--TEST--
+Bug #52854: ReflectionClass::newInstanceArgs does not work for classes without 
constructors
+--FILE--
+<?php
+class Test {
+}
+$c = new ReflectionClass('Test');
+var_dump(new Test);
+var_dump(new Test());
+var_dump($c->newInstance());
+var_dump($c->newInstanceArgs(array()));
+
+try {
+       var_dump($c->newInstanceArgs(array(1)));
+} catch(ReflectionException $e) {
+       echo $e->getMessage()."\n";
+}
+?>
+--EXPECTF--
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+object(Test)#2 (0) {
+}
+Class Test does not have a constructor, so you cannot pass any constructor 
arguments


Property changes on: php/php-src/trunk/ext/reflection/tests/bug52854.phpt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Revision
Added: svn:eol-style
   + native

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to