9

I do not understand I have this message appear (php8).

Thank you

Deprecated: Required parameter $to_addr follows optional parameter $to_name in /home/www/admin/OM/Mail.php on line 237

Deprecated: Required parameter $to_email_address follows optional parameter $to_name in /home/www/admin/OM/Mail.php on line 363

public function send(string $to_name = '', string $to_addr, string $from_name, string $from_addr, string $subject = '', bool $reply_to = false): bool
Harry
  • 357
  • 3
  • 4
  • 13

1 Answers1

12

In PHP 8, named parameters were added. This means that from now, parameters without a default value, are required to be BEFORE optional parameters.

An optional parameter is one with a default value: function example(string $optional = '');. We call them optional, well, because they are optional, as you can call the function as follows: example();.

Therefore, your prototype should change from:

public function send(string $to_name = '', string $to_addr, string $from_name, string $from_addr, string $subject = '', bool $reply_to = false): bool

to

public function send(string $to_addr, string $from_name, string $from_addr, string $to_name = '', string $subject = '', bool $reply_to = false): bool

You can read more about it here: https://www.php.net/manual/en/functions.arguments.php

Harm Smits
  • 437
  • 3
  • 10
  • 1
    Your first sentence doesn't really make sense. The addition of named parameters is completely coincidental to the deprecation; optional parameters before mandatory ones _never_ made sense. – IMSoP Dec 13 '21 at 17:44
  • In the internal discussion in PHP it was. – Harm Smits Dec 14 '21 at 13:50
  • The [change was merged in Jan 2020](https://github.com/php/php-src/pull/5067), and [the named parameters RFC](https://wiki.php.net/rfc/named_params) wasn't revived until May. Later, it was realised that named parameters accidentally allowed calls to omit the out-of-sequence parameter, which has been reverted in 8.1; see [this current thread](https://externals.io/message/116597). – IMSoP Dec 14 '21 at 14:45
  • 1
    No it would not be as those are end of life @Najeeb – Harm Smits Mar 12 '22 at 20:23