Skip to content

Commit

Permalink
Change the signature of ReflectionClass::newInstance to be compatible…
Browse files Browse the repository at this point in the history
… across all PHP versions, resolves #70
  • Loading branch information
lisachenko committed Jun 27, 2017
1 parent 4897038 commit 49e6cb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
},
"require": {
"php": ">=5.5.0",
"php": ">=5.6.0",
"nikic/php-parser": "^1.2|^2.0|^3.0"
},
"require-dev": {
Expand Down
12 changes: 10 additions & 2 deletions src/Traits/ReflectionClassLikeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,15 +843,23 @@ public function getStaticPropertyValue($name, $default = null)
* Creates a new class instance from given arguments.
*
* @link http://php.net/manual/en/reflectionclass.newinstance.php
*
* Signature was hacked to support both 5.6, 7.1.x and 7.2.0 versions
* @see https://3v4l.org/hW9O9
* @see https://3v4l.org/sWT3j
* @see https://3v4l.org/eeVf8
*
* @param mixed $arg First argument
* @param mixed $args Accepts a variable number of arguments which are passed to the class constructor
*
* @return object
*/
public function newInstance($args = null)
public function newInstance($arg = null, ...$args)
{
$args = array_slice(array_merge([$arg], $args), 0, \func_num_args());
$this->initializeInternalReflection();

return call_user_func_array('parent::newInstance', func_get_args());
return parent::newInstance(...$args);
}

/**
Expand Down

0 comments on commit 49e6cb8

Please sign in to comment.