Re: Two Issues regarding Named Parameters; want to understand the technicality
| From: | Larry Garfield | Date: | Thu, 09 Mar 2023 16:30:13 +0000 |
| Subject: | Re: Two Issues regarding Named Parameters; want to understand the technicality | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119676@lists.php.net to get a copy of this message | ||
On Wed, Mar 8, 2023, at 6:26 PM, Hamza Ahmad wrote:
> In my second project, I did not receive a warning when I passed the
> wrong parameters. To give you an example, I have two constructors:
> 1.
public function __construct(int $date, int$month, int $year)
>
> 2. public function __construct(string ...$names)
> When I initialized the latter object with the former object's
> signature i.e., `new LatterObject(date: 1, month: 1, year: 1970);
> `, I did not receive a warning of passing the wrong parameters.
Is the code in strict mode? If not, then that is the expected behavior. You should get a $names
array that has 3 associative keys, each with a numeric value that's been cast to a string.
In strict mode, I would expect that to give a TypeError, but not in weak mode.
--Larry Garfield