Re: [RFC] Safe Casting Functions
| From: | Rowan Collins | Date: | Thu, 23 Oct 2014 10:17:59 +0000 |
| Subject: | Re: [RFC] Safe Casting Functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78265@lists.php.net to get a copy of this message | ||
Marc Bennewitz wrote on 22/10/2014 20:12:
On 22.10.2014 10:37, Bob Weinand wrote:Those are two distinct types of default: - the default value to use when a programmer calls the function with fewer parameters (e.g. acceptsInt()) - the default value to use when a value is provided by the programmer, but turns out to be null at runtime (e.g. acceptsInt($_GET['foo']))I know we have that already discussed a lot now, but I’d like to expose my points on the return value here: I imagine code like (supposing that we ever will have scalar typehints): function acceptsInt (int $i = null) {NULL isn't a pointer for a default value - it's simply a type with no value - no more - no less. From your example: why do you accept NULL if you need a integer default value? function acceptsInt (int $i = 2) { ...if ($i === null) { $i = 2 /* default value */; } /* do something with $i */}