Re: Re: Construct Request

From: Date: Thu, 15 Apr 2004 17:31:13 +0000
Subject: Re: Re: Construct Request
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-9198@lists.php.net to get a copy of this message
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

« previous php.internals (#9198) next »