8. NEVER create a file of useful functions, even if it's called helpers.php This smacks of such a broken thinking process, it makes my teeth itch. If you have commonly-used functions, they should be integrated with the commonly-used parts of your code. Example function used for debugging: function preint_r($arr) { echo ' '; print_r($arr); echo ' '; } Where would something like this fit, if not a general helpers.php t…
PHP Commandments
21–30 of 117 posts
Re: PHP Commandments
#228. NEVER create a file of useful functions, even if it's called helpers.php This smacks of such a broken thinking process, it makes my teeth itch. If you have commonly-used functions, they should be integrated with the commonly-used parts of your code. Example function used for debugging: function preint_r($arr) { echo ' '; print_r($arr); echo ' '; } Where would something like this fit, if not a general helpers.php t…
Even better: you should write to a log file instead of to the screen (at debug level) for such things so you don't have to remove your (useful) debug statements before committing.
Re: PHP Commandments
#23Few comments.. #3 assumes that the variable came from user input, it's not necessarily bad. In some cases (i.e. dynamically switching from ORDER BY ASC/DESC) it's quite acceptable. But PDO + prepared statements for sure. #4 no need to use a library, htmlspecialchars/htmlentities are quite enough. #5 I think many frameworks/libraries can go here - why pick on one? #7 Mailgun, sengrid etc are becoming increasingly popu…
#3 should be #1, and further, it should read "If you insist on writing your own database layer, stop. You'll do it wrong in the worst possible way." PHP has institutionalized SQL value injection. mysql_query cannot be removed soon enough.
> mysql_query cannot be removed soon enough.
I agree. Bring on 5.5
Re: PHP Commandments
#24Re: PHP Commandments
#25Earlier quoted context omitted.
Couldn't agree more with E_ALL|E_STRICT. The current legacy system I am maintaining took me 2 weeks to clear up 90% of the NOTICE errors for using undefined variables etc. Dirty code is dirty, and it is because of this that PHP has received so much negative publicity.
The completely brain dead naming conventions for function names (or rather, the lack thereof) is another. PHP has grown organically, just like the web, to fill a very irregular shaped niche and it shows that history in all the gory little details. That said it made me more money than any other programming language combined (including C, but it's a very close second). Probably a lot of people have similar feelings tow…
Re: PHP Commandments
#268. NEVER create a file of useful functions, even if it's called helpers.php This smacks of such a broken thinking process, it makes my teeth itch. If you have commonly-used functions, they should be integrated with the commonly-used parts of your code. Example function used for debugging: function preint_r($arr) { echo ' '; print_r($arr); echo ' '; } Where would something like this fit, if not a general helpers.php t…
>Where would something like this fit, if not a general helpers.php type file? In debugging.php alongside with other debugging helpers?
What helper library should a function like the following exist in?
function array_select_keys(array $dict, array $keys)
{
$result = array();
foreach ($keys as $key) {
if (array_key_exists($key, $dict)) {
$result[$key] = $dict[$key];
}
}
return $result;
}Re: PHP Commandments
#27Can someone help me understand why a "helpers" or "utilities" file of functions is so bad? Asking humbly because I do that and don't yet understand why it's bad / the alternative.
Re: PHP Commandments
#28Earlier quoted context omitted.
The completely brain dead naming conventions for function names (or rather, the lack thereof) is another. PHP has grown organically, just like the web, to fill a very irregular shaped niche and it shows that history in all the gory little details. That said it made me more money than any other programming language combined (including C, but it's a very close second). Probably a lot of people have similar feelings tow…
Quick! Was it ($haystack, $needle) or ($needle, $haystack) ?
Re: PHP Commandments
#29Are people still using PHP without frameworks these days?
Couldn't help myself :(
Re: PHP Commandments
#30Can someone help me understand why a "helpers" or "utilities" file of functions is so bad? Asking humbly because I do that and don't yet understand why it's bad / the alternative.