1, "oranges" => 1, "mangoes" => 1, "tomatoes" => 1, "pickles" => 1);
if (isset($keys['mangoes'])) { ... }
6)key_exist
if(array_key_exists('mangoes', $keys))
vs
if (isset($keys['mangoes'])) { ... }
7)regexps
POSIX-regexps
vs
Perl-regexps
8)constants
UPPER case constans (TRUE, FALSE)
vs
lower case constans (true, false)
9)for
for ($i = 0; $i < FUNCTION($j); $i++) {...}
vs
for ($i = 0, $k = FUNCTION($j); $i < $k; $i = $i + 1) {...}
10)strings
"var=$var"
vs
'var='.$var
*/
/*
** Description:
** Optimization class. Provide functions for
** PHP code optimization.
**
** Author:
** Eugene Grigorjev (eugene.grigorjev@zabbix.com)
**/
//define("USE_PROFILING",1);
$starttime[]=array();
class COpt
{
/* protected static $starttime[]=array(); */
/* protected static */ function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
/* public static */ function profiling_start($type=NULL)
{
if(!defined('USE_PROFILING')) return;
global $starttime;
if(is_null($type)) $type="global";
$starttime[$type] = COpt::getmicrotime();
}
/* public static */ function profiling_stop($type=NULL)
{
if(!defined('USE_PROFILING')) return;
global $starttime;
$endtime = COpt::getmicrotime();
if(is_null($type)) $type="global";
echo "
\nTime to execute (".$type."): ". bcsub($endtime,$starttime[$type],6)." seconds!\n
";
}
}
?>