[php-src] Issue #11994: Optional arguments don't work with named parameters

From: Date: Fri, 18 Aug 2023 09:31:03 +0000
Subject: [php-src] Issue #11994: Optional arguments don't work with named parameters
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245204@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11994 Author: bestiony ### Description The following code: when using Laravel 10.14.1 , I added a method to the base controller class to handle the response in any controller if the result is a failed response , ```php <?php public function error( $data = null, $message = "", $code ) { $response = [ "code" => $code, "message" => $message, "status" => false, "data" => $data, ]; return response()->json($response, data_get($response, 'code', 200)) } ``` ideally I would use it like this : ```php <?php return $this->error(message:__('auth.failed'), code: 401,); ``` Resulted in this output: ``` App\\Http\\Controllers\\Controller::error(): Argument #1 ($data) not passed ``` But I expected this output instead: ``` { "code": 401, "message": "These credentials do not match our records.", "status": false, "data": null } ``` even though I am explicitly saying that $data has a default value thus it is optional ### PHP Version PHP 8.1.6 ### Operating System Windows 10

« previous php.bugs (#245204) next »