Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

null default-value parameter before required parameter is silently ignored #11485

Copy link
Copy link
@syranide

Description

@syranide
Issue body actions

Description

The following code:

<?php
function foobar(
    string|null $a = null,
    string $b
) {}

foobar(b: "x");

Resulted in this output:

Fatal error: Uncaught ArgumentCountError: foobar(): Argument #1 ($a) not passed

But I expected this error instead:

Deprecated: Optional parameter $a declared before required parameter $b is implicitly treated as a required parameter

To explain; $a does not end up being optional, and if you perform reflection on the property, it does not have a default-value. So PHP is silently ignoring the user-specified behavior. While it seems that PHP considers having optional properties in-front of required properties as invalid, it should at least issue a warning instead of silently changing expectations. If you put a string as default-value instead, it will emit the above depreciation notice.

PHP Version

PHP 8.2.7

Operating System

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.