php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70839 Convertion optional argument to variadic forbidden by LSP checks
Submitted: 2015-11-02 16:48 UTC Modified: 2020-01-23 14:24 UTC
From: nikic@php.net Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6.16 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2015-11-02 16:48 UTC] nikic@php.net
Description:
------------
Should be allowed and was allowed in 5.6. Off by one error caused by the variadic parameter no longer counting as an argument.

Test script:
---------------
class Foo {
    public function test($bar = null) {}
}

class Baz extends Foo {
    public function test(...$args) {}
}



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-02 16:49 UTC] nikic@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: nikic
 [2015-11-02 17:04 UTC] nikic@php.net
-PHP Version: 7.0.0RC6 +PHP Version: 5.6.16
 [2015-11-02 17:04 UTC] nikic@php.net
Actually this issue also exists in PHP 5.6 if you have more than one optional parameter:

class Foo {
    public function test($foo = null, $bar = null) {}
}

class Baz extends Foo {
    public function test(...$args) {}
}

The fact that it worked for one was just an accident that PHP 7 fixed.

We should allow changing any number of optional arguments to a variadic one in both 5.6 and 7.0.
 [2020-01-23 14:24 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2020-01-23 14:24 UTC] nikic@php.net
Fixed by https://github.com/php/php-src/pull/5059 in PHP 8.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC