Bug #74292 [Com]: Warning of incompatible declaration for ReflectionClass::newInstance()
Edit report at https://bugs.php.net/bug.php?id=74292&edit=1
ID: 74292
Comment by: bugs dot php dot net at majkl578 dot cz
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:
This is now a BC break in PHP 7.2 RC.
Related:
https://github.com/php/php-src/pull/2363
https://github.com/php/php-src/commit/9ffc6ca62f53431a4b32b30cdda8180142f47cdb
https://github.com/doctrine/common/pull/822
Previous Comments:
------------------------------------------------------------------------
[2017-06-27 16:39:32] lisachenko dot it at gmail dot com
BC break can be avoided in children classes with special signature hack, see https://3v4l.org/eeVf8 for details.
------------------------------------------------------------------------
[2017-04-01 16:21:56] php at duncanc dot co dot uk
https://bugs.php.net/bug.php?id=74035
------------------------------------------------------------------------
[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
Thread (6 messages)