Hello There,
What can be the common PHP coding pitfalls which probably many of us are not avoiding?
Hello There,
What can be the common PHP coding pitfalls which probably many of us are not avoiding?
Although this applies to most languages with any kind of library worth mentioning, one of the most common pitfalls is reinventing the wheel, or rewriting it, in the case of programming. Being deeply familiar with the available standard library, aware of the popular, compilable modules is one of the greatest assets an programmer can have. Being ignorant of or just plain ignoring these pre-made and time tested solutions is a huge pitfall.
One thing you should be warned is that PHP will allow you to code how ever you want, this by itself doesn't sound so bad, but it is, when the programmer doesn't have any programming basis.
So a little advice. When creating your first site, try to keep the code organized. Don't put a lot of php in html or a lot of html in php.
When you feel up to it, try looking at some php frameworks (a quick search in google will provide many links)
One last piece of advice. If you ever move away from PHP don't look back and say PHP was a bad language, it was you, it was all your fault! You were the bad programmer! :)
I'd say using PHP is a coding pitfall, but then again I've been there and back. You weren't there, man! You weren't there...
Easy.... Echoing HTML!
It pisses me off, why do people echo HTML? For instance:
echo("<ul>")
foreach($arr as $key => $value) {
echo(" <li>".$value."</li>");
}
echo("</ul>");
Hey, do you remember that PHP is an embedded language? Probably not as your echoing out hundreds of lines of HTML just to make sure your code looks pretty when you view source.
mysql_query("SELECT * FROM foo WHERE bar = '" . $_GET["baz"] . "'");