Forgot your password?
typodupeerror

Comment: It's correct, but but not complete (Score 2, Insightful) 165

by MacFanMR (#15663664) Attached to: PHP Hacks
All of those observations are true, but that doesn't mean you shouldn't use PHP. As with any tool, you must consider the user, their skill level, and the project requirements when making your decision.

Many of PHP's inconsistencies stem from the fact that it is an open source language. While it has likely changed now, many functions were accepted into the source without anyone ensuring a consistent naming scheme, parameter order or behavior. To maintain backward compatibility for what is now a very large user base, this cannot be easily changed at this point.

Several of the examples of redundant functions are not redundant at all. The escaping functions relate to the specific database they are escaping the data for. Oracle requires that things be escaped differently than MySQL, a single function wouldn't work.

That aside, there are many functions that perform tasks you could accomplish in other ways. For instance, finding if a string contains another string. I might use strpos('mystring', 'my') but there is also a function that is named specifically for the purpose of finding whether a string contains another string. That function would return a simple true/false while my example would actually return the position of the substring or false but I can interpret it to tell me what I need to know. My guess was that the extra functions are an attempt to make the language accessible to less experienced programmers. For me, I would rather write my own functions as needed than muddy the PHP parser with extra functions, but I'm not on the development team so it's not my decision to make.

PHP has namespaces though they are not formal and therefore not as efficient. For example, all the MySQL functions begin with mysql_ and pSpell functions begin with pspell_. Starting with PHP5 and full OOP support, they now have class based namespaces like SOAPServer::addFunction(). Each namespace regardless of type, represents a package compiled into PHP. Though the default compile comes with many packages installed, you can decrease the number of functions by compiling without support for DBs and other packages you don't need. This would decrease the number of functions PHP is parsing for (correct me if I'm wrong on this.)

Perl may be compact, but if you notice in the examples, for someone who isn't familiar with Perl, the code provided wouldn't be immediately understandable, and Perl code can be optimized and obfuscated even more than that.

On the flip side is Java, which at its core is compact, but with the Java standard library of methods, there are nearly unlimited numbers of methods to do just about anything and everything you could ever think of. Add to that the frameworks that exist: struts, beans, servlets, jsp... just to scratch the surface and we find that Java is infinitely flexible and powerful. For those that know it, it is probably the greatest thing ever, but for someone starting out, it is incredibly overwhelming.

If you use PHP and it fulfills your needs, then keep using it. If you run into a lot of limitations or frustrations because it can't do things you could do in xyz language, or because you are building projects that become difficult to maintain due to their scale, then you might want to explore other options. Ruby/Perl/Java/ASP/Cold Fusion has its pros and cons as much as PHP or anything else. It's up to you as the professional to evaluate your specific needs and options and make the right decision for you.

Michael

"An entire fraternity of strapping Wall-Street-bound youth. Hell - this is going to be a blood bath!" -- Post Bros. Comics

Working...