[PHP-BUG] Bug #74292 [NEW]: Warning of incompatible declaration for ReflectionClass::newInstance()

[email protected] ("[email protected]")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             ramsey
Operating system: 
PHP version:      master-Git-2017-03-22 (Git)
Package:          Reflection related
Bug Type:         Bug
Bug description:Warning of incompatible declaration for ReflectionClass::newInstance()

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 bug report at https://bugs.php.net/bug.php?id=74292&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74292&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74292&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74292&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74292&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74292&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74292&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74292&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74292&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74292&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74292&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74292&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74292&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74292&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74292&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74292&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74292&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74292&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74292&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74292&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74292&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.