I’ve been working at KASA Capital for about 7 months and I feel like I’ve gotten a good handle of some of the more “gritty” details of how PHP works. Unfortunately though, it means I have a running list of annoyances with the language—some more difficult to deal with than others.
-
Keywords are case-insensitive. Being able to write the word
trueusing uppercase or lowercase may be aestheticly useful depending on the context, but I don’t think there would be any situation where writtingtRuEorTRuewould be a good idea. The last thing I want to see when optimizing someone else’s code is variable-case keywords. Even using all uppercase keywords is highly suspicious, and when I actually saw this the other day, I found the code almost unreadable. I also think that having case-sensitive keywords in PHP would improve parser times, but I haven’t tested this theory. What I do know is that other interpreted languages like Python have strict rules for keywords, and Python code tends to run much faster than PHP code (of course this is not a proof though and may actually have no correlation). -
isset(),unset(), andNULLare confusing. A while back, I wrote a whole bunch of Python code. Transitioning back to PHP for work was difficult first because of the semicolon use in PHP, but second because of PHP’s (lack of) variable declaration. Technically, the documentation is very specific, but most implementations have a low setting for the defaulterror_reportinglevel so many programmers have learned to be lazy with variables. After a security audit of your site though, you would probably learn very quickly to code usingerror_reporting(E_ALL|E_STRICT). -
When using double quotes with a string, you may include PHP variables in it thus having PHP parse the string. This really isn’t that big of an issue since it is well documented, but most PHP programmers I’ve run into don’t understand that calling the parser takes additional resources which may in turn slow down your code.
-
Magic Quotes. If you have ever had to deal with magic quotes you will understand that this is the single most terrible aspect of the language to ever happen. The theory of it might have been okay, but in practice it is extremely frustrating–not to mention that against recommendations, debian (and thus Ubuntu) packages of PHP have magic quotes on by default. I am so glad this was deprecated in 5.3.
-
I can’t
echoHTTP headers. The only way to manipulate HTTP headers is to use theheaderfunction. Under most circumstances this is okay, but there are a unique instances like streaming content in a proxy-like manner where the headers are important and it would be too intensive to parse the stream, so I would like to simply be able toechothem. When using PHP in CLI mode, I can use the-qflag to turn header output off, but this is not available in CGI mode, which most people use.
Even with all that, I do still use PHP at work; but constantly trying to write clean, efficient code goes a long way.
i’m pretty sure neither the case insensitivity of keywords nor the double-quote variable parsing really add that much a speed penalty. the php devs posted an article about php performance myths some months ago, but i can’t find it right now.
really, if you have to use single-quotes over double-quotes because only the last ones provide the performance you need it may be better to switch to another platform altogether. that said, i never use double quotes for strings myself, because i don’t like the mixture of string constants and variables very much. moreover, with all the object and array syntax added, you have to use more complex markup anyway (uhm, “{}” ;)), minimizing the advantages. also IDEs have a harder time parsing variables out of strings for autocompletion and stuff. thanks, no double quote strings for me.
Case insensitive keywords doesn’t mean mixing of case like trUe, it’s mainly for either lower or upper case like true and TRUE. Yes, double quote is expensive than single quote when variables are included in the string.
You want to echo headers? Such as in perl? I’m not sure to understand the difference between using header(), however you can simply activate output buffering and you will be able to call header() wherever you want.
PHP is lame, that’s why you submitted your post to Digg, which is written in PHP?
“but most PHP programmers I’ve run into don’t understand that calling the parser takes additional resources which may in turn slow down your code.”
Cool. Calling the parser will increase the time your code runs with 0.00001 seconds. At the same time you will lose 1 second of your life for every place where you need to concatenate instead of placing the variables in the string. Hardware is cheap, developer’s time is expensive (at least the time of the developers who are doing something useful).
[...] PHP is Lame, 5 Reasons Why « Joseph Piché [...]