mirror of
https://github.com/php/php-src.git
synced 2024-12-17 22:09:12 +08:00
- Fix #52854 (ReflectionClass::newInstanceArgs does not work for classes without constructors
This commit is contained in:
parent
224bfb38f7
commit
5a1e9d1d6b
@ -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);
|
||||
|
28
ext/reflection/tests/bug52854.phpt
Normal file
28
ext/reflection/tests/bug52854.phpt
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user