Thank you for taking a moment to evaluate a serious request by a serious php developer that is responsible for a development company of 15 employees.
In order to keep our code as clean and error free as possible, we opt to develop in the E_ALL error mode, and register_globals = off. This comes with several challenges that one does not normally encounter.
We define and cast incoming script data variables at the top of each script, so they are always defined and contain a valid value. Before E_ALL was used, the form of this was:
$nCustID = (integer) $_POST['nCustID'];
and from that point on, the variables $nCustID and $sName would be used. However when we started using E_ALL, these lines of code would throw E_NOTICE level errors when the variable did not exist in the $_POST array. So now, we use the form:
$nCustID = (integer) (isset($_POST['nCustID']) ? $_POST['nCustID'] : 0));
I know that writing a line like the following would be a solution, but when evaluated closely, it is a very slow and clumsy one, especially if you are using a custom error handler.
@ $nCustID = (integer) $_POST['nCustID'];
There is nothing wrong with writing lines of code like $nCustID = (integer) (isset($_POST['nCustID']) ? $_POST['nCustID'] : 0)); everywhere, but it does tend to make the code very messy.
The feature that I am proposing is a language construct, and therefore would need integrated into the ZEND engine. It is very simple, and would be modeled after isset().
Function: setor(arg1, arg2) -- if parameter 1 is set, then return it, else evaluate and return parameter 2.
Example: $nCustID = (integer) setor($_POST['nCustID'], 0);
I would imagine that the ( ? : ) operator only evaluates the second or third argument if they are actually used, and the setor() function should behave the same. Therefore, it would allow for expressions such as:
echo setor($required_variable, die('error...'); or echo setor($error, ''); or echo setor($sMessage, $sDefaultMessage). or $z = setor($_GET['z'], 'Default');
As you can see, it would reduce and un-duplicate quite a bit of code, making PHP an even more easy to use language. Please evaluate this request carefully, and then let me know your thoughts on it.
Sincerely,
Jason Garber President and Chief Technology Officer IonZoft, Inc. :: 814.742.8030
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php