Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling class method with unnecessary parameters does not throw exception #17690

Closed
fazliddin opened this issue Feb 4, 2025 · 5 comments
Closed

Comments

@fazliddin
Copy link

Description

The following code:

final class Actions
{
...
    public function add(string $pageName, Action|string $actionNameOrObject): self
    {
        return $this->doAddAction($pageName, $actionNameOrObject);
    }
...
}

$obj = new Actions;
$obj->add(Crud::PAGE_EDIT, Action::SAVE_AND_CONTINUE, function (Action $action)
{
    return $action->setIcon(false)->setLabel(false);
})

Resulted in this output:

No error is shown

But I expected this output instead:

Method add does not have third parameter

PHP Version

PHP 8.2.27

Operating System

Ubuntu 22.04

@MorganLOCode
Copy link

This has always been true of any user-defined function; they're available through functions such as func_get_args.

@fazliddin
Copy link
Author

But I did not use ...$arg notion, and such silent behavior makes debugging hard.

@nielsdos
Copy link
Member

nielsdos commented Feb 4, 2025

That's true. This is allowed even without a variadic parameter for BC reasons, as func_get_args predates variadics.
Changing this would need an RFC.

@Disservin
Copy link
Contributor

@iluuu1994
Copy link
Member

As explained, this is not a bug. Changing this has large userland implications and thus likely requires not only an RFC but also a multi-year migration path.

@iluuu1994 iluuu1994 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants