From 5a1e9d1d6b1326175b1327919786364a0d1b4a58 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Schl=C3=BCter?= Date: Sun, 21 Nov 2010 12:24:09 +0000 Subject: [PATCH] - Fix #52854 (ReflectionClass::newInstanceArgs does not work for classes without constructors --- ext/reflection/php_reflection.c | 2 +- ext/reflection/tests/bug52854.phpt | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ext/reflection/tests/bug52854.phpt diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 9f06deeabf..fce1b583c4 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4296,7 +4296,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) 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); diff --git a/ext/reflection/tests/bug52854.phpt b/ext/reflection/tests/bug52854.phpt new file mode 100644 index 0000000000..94f79d858b --- /dev/null +++ b/ext/reflection/tests/bug52854.phpt @@ -0,0 +1,28 @@ +--TEST-- +Bug #52854: ReflectionClass::newInstanceArgs does not work for classes without constructors +--FILE-- +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 -- 2.40.0