Bug #74292 [Com]: Warning of incompatible declaration for ReflectionClass::newInstance()
| From: | php at duncanc dot co dot uk | Date: | Sat, 01 Apr 2017 16:21:58 +0000 |
| Subject: | Bug #74292 [Com]: Warning of incompatible declaration for ReflectionClass::newInstance() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208258@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74292&edit=1
ID: 74292
Comment by: php at duncanc dot co dot uk
Reported by: ramsey@php.net
Summary: Warning of incompatible declaration for
ReflectionClass::newInstance()
Status: Open
Type: Bug
Package: Reflection related
PHP Version: master-Git-2017-03-22 (Git)
Block user comment: N
Private report: N
New Comment:
https://bugs.php.net/bug.php?id=74035
Previous Comments:
------------------------------------------------------------------------
[2017-03-22 17:41:00] kelunik@php.net
The documented signature is variadic, but it seems like the signature wasn't implemented like
that before. The behavior in PHP 7.2 is the right one based on the documentation, but I'm not
sure it's worth the BC break.
------------------------------------------------------------------------
[2017-03-22 17:34:21] ramsey@php.net
Description:
------------
In PHP 7.2.0-dev, when extending ReflectionClass and overriding the newInstance() method, I am
receiving a warning about an incompatible declaration (see actual result for warning message).
In PHP 5.6.30 and 7.1.3, I do not receive this warning. This is a possible BC break in 7.2.
This warning turned up in the PHP nightlies on Travis CI for packages depending on the
goaop/parser-reflection library. See here for details: https://github.com/goaop/parser-reflection/issues/70
I have confirmed the problem locally using the following test script, tested against 5.6.30, 7.1.3,
and 7.2.0-dev (built 2017-03-22 from master).
Test script:
---------------
<?php
class Foo {}
class MyReflectionClass extends \ReflectionClass
{
public function newInstance($args = null)
{
return call_user_func_array('parent::newInstance', func_get_args());
}
}
$fooReflected = new MyReflectionClass(Foo::class);
$fooInstance = $fooReflected->newInstance();
var_export($fooInstance);
Expected result:
----------------
$ php reflection-class-error.php
Foo::__set_state(array(
))
Actual result:
--------------
$ php reflection-class-error.php
PHP Warning: Declaration of MyReflectionClass::newInstance($args = NULL) should be compatible with
ReflectionClass::newInstance(...$args) in /Users/ramsey/Desktop/reflection-class-error.php on line
11
Warning: Declaration of MyReflectionClass::newInstance($args = NULL) should be compatible with
ReflectionClass::newInstance(...$args) in /Users/ramsey/Desktop/reflection-class-error.php on line
11
Foo::__set_state(array(
))
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74292&edit=1