setPlaceholders
setPlaceholders copied to clipboard
Undefined index
Hi, this is just a minor matter.
While I develop, I always have an eye on the error.log file. Using setPlaceholders with access to some get Values produced Output on every request. Therfor I have edited the setplaceholders.class.php
file.
I am sorry to not changing it and making a pull request, but maybe you would like to take these lines and place them in Place at line 60:
if ($fieldPrefixes[0] === 'get') {
$var = substr($fieldName, 4);
return isset($_GET[$var])?$_GET[$var]:'';
}
if ($fieldPrefixes[0] === 'post') {
$var = substr($fieldName, 5);
return isset($_POST[$var])?$_POST[$var]:'';
}
if ($fieldPrefixes[0] === 'request') {
$var = substr($fieldName, 8);
return isset($_REQUEST[$var])?$_REQUEST[$var]:'';
}
I would be thankful if you could add this code. Thank you.
When I code I always check isset()
before I access anything. From Java I know that it costs less then throwing an exception.
Now as I suggested this for your code, i was not sure if it is wise to do hat in PHP too, so I ran a test for the first Time to find it out:
<?php
echo "<pre>";
$x=array();
ini_set('display_errors','0');
$max=100000;
$key='gibtsNicht';
$before = microtime(true);
for ($i=0 ; $i<$max ; $i++) {
$a=$x[substr($key, 4)];
}
$after = microtime(true);
$total = $after-$before;
$t1= "Zeit Total: $total ;".$total/$i . " ms/serialize\n";
$before = microtime(true);
for ($i=0 ; $i<$max ; $i++) {
$var=substr($key, 4);
$a=isset($x[$var])?$x[$var]:'';
}
$after = microtime(true);
$total = $after-$before;
$t2= "Zeit Total: $total ;".$total/$i . " ms/serialize\n";
echo "\nErgenisse:";
$xxx=$t1;echo "\n".'$t1: '.$xxx;
$xxx=$t2;echo "\n".'$t2: '.$xxx;
echo "</pre>";
The result shows that it is OK to check first. It will not make code Slower. Here is the result:
$t1: Zeit Total: 0.69480609893799 ;6.9480609893799E-6 sec/serialize
$t2: Zeit Total: 0.047554016113281 ;4.7554016113281E-7 sec/serialize
Regards and Thanks for your work, Hannes