The thing I like about the suggestion over implementing
the function in script is the ability to skip the call to
a function that provides the default.  In the following
example, slowFunc() simulates a slow function using a sleep,
but you can imagine any function call with a performance
hit.  The script version of setor takes the performance hit
whether it needs to or not.  The internal version could 
only take the hit when necessary.  Likewise for avoiding
calls that have more effects than generating a default.

<?php
error_reporting(E_ALL | E_STRICT);
function slowFunc() {
    sleep(10);
    return 2;
}

function getor($param, $default){
    if (!isset($param)) {
        return $default;
    }
    return $param;
}
$_GET['whatever'] = 5;
$x = getor(@$_GET['whatever'], slowFunc());  // Long wait for no-op
var_dump($x);
flush();
unset($_GET['whatever']);
$x = getor(@$_GET['whatever'], slowFunc());
var_dump($x);
?>

- Todd

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to