Skip to content

Allow making parameters nullable #391

Closed
@danog

Description

Starting from PHP5.3, classes can make interface method parameters nullable.

Code:

<?php

interface a 
{
    public function test($a);
}

class b implements a
{
    public function test($a = null) {}
}

var_dump(new b);

Result:

-> linux
-> app:run 
-> install 

Fatal error: Uncaught Error: Declaration of b::test($a = null) should be compatible with a::test($a) in res://p.php on line 10, position 12
Stack Trace:
#0 {main}
  thrown in res://p.php on line 10

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions