note 91412 added to function.error-reporting
| From: | misplacedme at gmail dot com | Date: | Tue, 09 Jun 2009 21:25:50 +0000 |
| Subject: | note 91412 added to function.error-reporting | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156668@lists.php.net to get a copy of this message | ||
I always code with E_ALL set.
After a couple of pages of
<?php
$username = (isset($_POST['username']) &&
!empty($_POST['username']))....
?>
I made this function to make things a little bit quicker. Unset values passed by reference
won't trigger a notice.
<?php
function test_ref(&$var,$test_function='',$negate=false) {
$stat = true;
if(!isset($var)) $stat = false;
if (!empty($test_function) && function_exists($test_function)){
$stat = $test_function($var);
$stat = ($negate) ? $stat^1 : $stat;
}
elseif($test_function == 'empty') {
$stat = empty($var);
$stat = ($negate) ? $stat^1 : $stat;
}
elseif (!function_exists($test_function)) {
$stat = false;
trigger_error("$test_function() is not a valid function");
}
$stat = ($stat) ? true : false;
return $stat;
}
$a = '';
$b = '15';
test_ref($a,'empty',true); //False
test_ref($a,'is_int'); //False
test_ref($a,'is_numeric'); //False
test_ref($b,'empty',true); //true
test_ref($b,'is_int'); //False
test_ref($b,'is_numeric'); //false
test_ref($unset,'is_numeric'); //false
test_ref($b,'is_number'); //returns false, with an error.
?>
----
Server IP: 209.41.74.194
Probable Submitter: 24.248.212.7
----
Manual Page -- http://www.php.net/manual/en/function.error-reporting.php
Edit -- https://master.php.net/note/edit/91412
Del: integrated -- https://master.php.net/note/delete/91412/integrated
Del: useless -- https://master.php.net/note/delete/91412/useless
Del: bad code -- https://master.php.net/note/delete/91412/bad+code
Del: spam -- https://master.php.net/note/delete/91412/spam
Del: non-english -- https://master.php.net/note/delete/91412/non-english
Del: in docs -- https://master.php.net/note/delete/91412/in+docs
Del: other reasons-- https://master.php.net/note/delete/91412
Reject -- https://master.php.net/note/reject/91412
Search -- https://master.php.net/manage/user-notes.php