DEV Community

Seong Bae
Seong Bae

Posted on

9 1 1 1 2

Unknown named parameter in PHP 8

I am adding hook support to one of my Laravel projects and was using a lot of the code from this wonderful Laravel Hook package at https://github.com/esemve/Hook. However, this package was built for Laravel 5 and PHP 7. I am using Laravel 10 and PHP 8 so there were some issues I had to fix.

One of the issues was "Unknown named parameter" on the following line:

$output = $output . call_user_func_array($function['function'], $params);

Ih PHP 7, the keys in $params were ignored. However, in PHP 8, they are not - keys are converted to named parameters.

So if $params was following:

$params = ['key1'=>'value1', 'key2'=>'value2']

key1 and key2 would be converted to $key1 and $key2 in PHP 8 when they were simply ignored in PHP 7. This was a breaking change in PHP 8.

If you ever come across this issue, a simple fix it to convert $params to array values. Changing to following should fix the issue.

$output = $output . call_user_func_array($function['function'], array_values($params));

Happy coding!

Sources:

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
lalami profile image
Salah Eddine Lalami

Hi @seongbae , welcome to dev community

Collapse
 
gallomaf profile image
Francesco Massimo Gallo

Thanks a lot! After hours of debugging you saved my night :-)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →