Marc Bennewitz wrote on 22/10/2014 20:12:
On 22.10.2014 10:37, Bob Weinand wrote:
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) {
if ($i === null) {
$i = 2 /* default value */;
}
/* do something with $i */
}
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) { ...
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']))
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php