note 104404 deleted from functions.arguments by cmb

From: Date: Sun, 10 Nov 2019 12:58:16 +0000
Subject: note 104404 deleted from functions.arguments by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213018@lists.php.net to get a copy of this message
Note Submitter: jacob at jacobweber dot com ---- This page states: "Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected." There seems to be one exception to this. Say you're using type-hinting for an argument, but you want to allow it to be NULL, and you want additional required arguments to the right of it. PHP allows this, as long as you give it the type-hinted argument a default value of NULL. For example: <?php function sample(ClassA $a = NULL, $b) { } sample(new ClassA(), ''); // success sample(new ClassB(), ''); // failure; wrong type sample(NULL, ''); // success sample(new ClassA()); // failure; missing second argument ?>

« previous php.notes (#213018) next »