Skip to content

Commit 49e6cb8

Browse files
committed
Change the signature of ReflectionClass::newInstance to be compatible across all PHP versions, resolves #70
1 parent 4897038 commit 49e6cb8

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
65
- 7.0
76
- 7.1

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
},
2424
"require": {
25-
"php": ">=5.5.0",
25+
"php": ">=5.6.0",
2626
"nikic/php-parser": "^1.2|^2.0|^3.0"
2727
},
2828
"require-dev": {

src/Traits/ReflectionClassLikeTrait.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,23 @@ public function getStaticPropertyValue($name, $default = null)
843843
* Creates a new class instance from given arguments.
844844
*
845845
* @link http://php.net/manual/en/reflectionclass.newinstance.php
846+
*
847+
* Signature was hacked to support both 5.6, 7.1.x and 7.2.0 versions
848+
* @see https://3v4l.org/hW9O9
849+
* @see https://3v4l.org/sWT3j
850+
* @see https://3v4l.org/eeVf8
851+
*
852+
* @param mixed $arg First argument
846853
* @param mixed $args Accepts a variable number of arguments which are passed to the class constructor
847854
*
848855
* @return object
849856
*/
850-
public function newInstance($args = null)
857+
public function newInstance($arg = null, ...$args)
851858
{
859+
$args = array_slice(array_merge([$arg], $args), 0, \func_num_args());
852860
$this->initializeInternalReflection();
853861

854-
return call_user_func_array('parent::newInstance', func_get_args());
862+
return parent::newInstance(...$args);
855863
}
856864

857865
/**

0 commit comments

Comments
 (0)