Keith Devens .com |
Wednesday, July 9, 2008 | ![]() |
| That is because you crazy! – Ikea | ||
|
| ← References and pointers | "I'm much better-looking online" → |

Simon Willison (http://simon.incutio.com/) wrote:
Keith (http://www.keithdevens.com/) wrote:
Heh, then maybe you can help me get mine to work... 
Keith (http://www.keithdevens.com/) wrote:
The worst thing about all this is that I had (and still have, of course) code that works, but that I have to waste hours of my life rewriting because someone (apparently arbitrarily) decided to deprecate a feature without considering the consequences.
Ben (http://www.trollscript.de/blog) wrote:
Well, I can relate to the "reference angst" in PHP. It's currently very confusing, though it's not a very new situation. Reference support until now has always been sketchy and impartial. What strikes me particularly as odd is the relationship between arrays and references. For instance,
$foo->test(array(&$bar));
where bar is an object does NOT trigger the default error warning. I don't know if it rather should or not, or if it's a perfectly legal PHP statement. Anyway, wrapping a one-element array around the variable enables provides a kludge for optionally passing references, if test() looks like this:
function test($param = null) {
if (isset($param)) {
$param[0]->add('hi');
}
}
PHP horrid? Perhaps. Inconsistent? Indeed.
Moss Collum (http://www.m14m.net/) wrote:
I hate PHP
Now there's something all of us, liberal or conservative, can agree on.
Keith (http://www.keithdevens.com/) wrote:
Definitely inconsistent. So much so that I constantly have to look to the reference to find out which functions take parameters in which order, since "needle" and "haystack" are so often reversed.
"Horrid" includes other major pain in the butt features like magic_quotes, trans_sid, etc.
82.36.196.38 wrote:
Ben,
The reason for that is that a copy of the array is made (including a copy of the reference).
Inconsistency and bad planning are my two main gripes with PHP. Magic quotes, for example. "I know, let's put backslashes into strings from the user, just on the off-chance that the author is going to dump them into a database without quoting them! Who cares about sane authors?"
Not to mention the fact that it's impossible to use nl2br() with current versions of PHP and valid HTML (it only generates XHTML-style br elements).
Keith (http://www.keithdevens.com/) wrote:
Not to mention the fact that it's impossible to use nl2br() with current versions of PHP and valid HTML (it only generates XHTML-style br elements).
Yeah, and highlight_string, et al, still use <font> tags to do the highlighting. In my markup library, where I want to allow PHP code highlighting, I had to do a regular expression replacement on the generated string to replace '<font color="' with '<span style="color: ' and '</font>' with '</span>'.
Keith (http://www.keithdevens.com/) wrote:
Actually, I don't know what your problem is with XHTML style <br /> tags. AFAIK, they should work with everything... that's a feature, not a problem. I didn't read your comment carefully enough originally.
Keith (http://www.keithdevens.com/) wrote:
Grr... one more correction. I didn't do a regular expression replacement like I said above... just a plain string replacement.
Sterling Hughes (http://www.edwardbear.org/blog) wrote:
call time pass by reference is sometimes necessary, in this case just use it. You'll only get these errors if you are using E_NOTICE. E_NOTICE just tells you cases where you could be doing something that is possibly wrong, not necessarily wrong.
Its sorta like: "Tell me when I might be doing something stupid mode." It doesn't mean you actually did something wrong.
Most of the object inconsistencies will be fixed in PHP5, btw.
Keith (http://www.keithdevens.com/) wrote:
At first I thought they were notices, but since the error messages said "Warning:" and not "Notice:" I figured they were E_WARNING level messages. Thanks Sterling, I may just go and turn off E_NOTICE's for those and save myself the headache.
The problem, for people like me who want to write libraries, is that we can't just worry about our own configurations. So for every function I may have to turn off error_reporting() of E_NOTICES. 
Sterling, do you know why call-time pass-by-reference was deprecated in the first place?
Harry Fuecks wrote:
If you're looking for some entertainment, how about trying HTMLSax instead?
Thanks to some great input via Sitepointforums, managed to get it ramped up to be almost as fast as the native PHP XML extension. I've also done my best to make the API as similar as possible so it should mean only minor modifications to a class currently using Expat. Thats the downside though - the handlers must be available via an object. Oh and HTMLSax wont warn you if the XML was badly formed.
But $parser->set_object($this) will mean $this is referenced...
Scott Johnson (http://feedster.com/blog/) wrote:
Hi Keith,
Well I'll definitely agree with you on php's inconsistencies. They suck. But different languages work for different folks. PHP works for me so I'll stay with it. It does sound like you're just not happy and maybe Python is a better place for you (though it would be a shame to lose you although I'll benefit since I'll learn from your learning process (and blogging about it)).
Best
Scott
anand (http://masterofweb.com) wrote:
Personally I prefer ruby though I do a lot of plugin development in PHP for nucleus.
Keith (http://keithdevens.com/) wrote:
Just wanted to update this post: The errors given to complain about call time pass by refererce are definitely E_WARNINGs and not E_NOTICEs.
Markus wrote:
about PHP being inconsistent, I can only agree
see http://tnx.nl/php.txt for more
Keith (http://keithdevens.com/) wrote:
Hey, I think that's the article I linked to here, but the link broke almost immediately.
Hong (http://www.k-edge.com) wrote:
Workaround for "Call-time pass-by-reference has been deprecated":
call_user_func_array(array(&$obj,$method),array(&$arg1,$arg2));
Jeff wrote:
I find it funny that this site is powered by PHP.
Keith (http://keithdevens.com/) wrote:
tomm wrote:
I just was curious about PHP, since our apprentice loves it a lot... So far, I resisted to touch anything else than Perl and Bourne Shell, and I'm happy with it. "Give the customer what he wants, not what he needs" - oh god, I'm sick of it. I've seen guys claiming to be pros in any known language. The first Perl snippets I encountered said all enough...
Ah, PHP is perfectly suited for the unexperienced, wannabe hacker. Yes, you get some results quickly. Just an example which gave me a really bad impression about PHP: Compare PHP's DB stuff with Perl's DBI interface.
Stick at your programming language of your choice, and really learn how to code. Keep it simple (not stupid, simple
. Write concepts. End up with clean, well commented code, and enjoy! 
Cheers from Switzerland,
tomm
sotto wrote:
Thanks! ... thanks to your post i finally found out how i can pass my parameters by reference with call_user_func ... :-)
Perlisbetter wrote:
Not to mention that marrying design elements with logic is
bad for sites where you actually care about design. It means your designers must code around logic, and programmers usually suck at final design, and having different people fighting over the same files is a pain. That's why I use templates for design, and PERL for logic. PERL's better anyway. No qq with PHP is enough for me to not want to use it. Having to escape quotes is a ridiculous and unnecessary pain in the neck.
ME wrote:
If you hate PHP what do you use then..and why are you still using PHP?
Keith (http://keithdevens.com/) wrote:
Because PHP site == done, while {other language} site == not done. Plus, that language vs. platform thing I mentioned a few comments up. PHP is a crappy language, but a pretty fair platform for making web pages. And PHP 5 is less crappy.
Hendy Irawan (http://dev.gauldong.net/) wrote:
I hate PHP. PHP sucks.
Unfortunately there's no entirely feasible alternative that can replace PHP completely. By "PHP" is also mean "PHP and libraries and applications built on it".
Eric Boutin wrote:
I hate PHP too; so many bugs !!! I find one every week. Plus your not even shure your application is going to run on the next php release. That sucks really as soon as I can I move to jsp/j2ee damn php
Elliot Anderson wrote:
I found if you want to unshift an array with references, you have to write your own function to take the array, reverse it, do something like $array[] = &$reference; and then reverse again.
Mobile developer (http://cellphonesclub.com/wp/) wrote:
I don't hate PHP, but now I battle with parsing of XML where are used rare char-set CP850 (yeh .. "Deutsche Post World Net" still use it). PHP does not support it and PHP does not support Unicode - one more nightmare of PHP ...
insta wrote:
Some problems with PHP have nothing to do with the language, but the programmer. Keith, why don't you try checking the INI file for things like how to wrap the source code? You can overwrite values with ini_set. They default to <font, but you can change them to <span
That said, PHP still sucks. Far too easy barrier of entry lets people vomit all over a keyboard and PHP will run it. Then they put on their resume that they're "expert PHP developers", and take my (and other skilled developers') job for half the pay, only to ruin everything a month later with their ineptitude in the language.
Not that I work with anyone like that ...
Keith (http://keithdevens.com/) wrote:
Keith, why don't you try checking the INI file for things like how to wrap the source code? You can overwrite values with ini_set. They default to <font, but you can change them to <span
No, you can't. Here's the documentatation on PHP's syntax highlighting: first the ini settings, and next the documentation for highlight_string. It seems that it uses "<span..." in PHP 5 and "<font..." in PHP 4, with no way to change that in either version.
Before "blaming the programmer" (i.e. me) how about you show me in the documentation where it can be changed like you say?
Hannibal wrote:
Is there anything you don't hate? PHP, ASP, ASP.NET? I'm sure you are going to hate RoR too.
You are a hater.
Keith (http://keithdevens.com/) wrote:
I don't hate Python :-P
Ivo wrote:
Ai, Python. We (two average experienced Linux system administrators) have spent one full working day on trying to get Python to run as a module on Apache. Tweaking some .py file that came with the package finally 'did' it.
PHP is installed and runs correctly in seconds (with good package manager, that is
).
Not flaming Python, just one of my annoyances 
Michael Goodell (http://peehpee.com) wrote:
Yes PHP is the anti-Christ! Tell your friends! The end is near!
Just a few of my reasons:
1. Post-mortem debugging. Adds hours to finding the simplest bugs. I stopped doing post-mortem debugging in the late 1980's
2. OOP / OOD is an afterthought and does it show!!!
3. Can shut off error reporting! I guess the problem does not exist if you can't see it.
4. Obvious syntax error go unnoticed and Pee-H-Pee thinks all is well. ie foo shoud be $foo and nothing is said.
5. Exception handling? Pee-H-Peez structured exception handling in 5.x is laughable. Nice try boys.
6. It's obvious Pee-H-Pee grew out of a set of PERL scripts.
7. Can scatter settings all over the place. No structure to any applicaitons.
Bottom line: Pee-H-Pee? It's the VB3 for the web.
In other words:
"You can only polish a turd so much before it starts to smear!"
Personally, when the enterprise application calls I break out Java / Servlets / JSP. Apache->Tomcat->FreeBSD!!
Anyone ever gone away from JSP / Java / Servlets to Pee-H-Pee? Anyone who has done so for valid reasons? Not becuase you don't get Java? Anyone? . . . . Didn't think so.....
M.Hirsch (http://www.vrdevelopers.de/) wrote:
Another problem related to references that I recently encountered:
I tried to write a (php) replacement for the mysqli functions because my script is supposed to also work without this extension.
90% through writing the wrapper, I noticed that there is no way to replace mysqli_stmt_bind_result()
Variable function arguments don't support references. 
Dave wrote:
Some interesting comments on this blog. Coming from a C++ background I can understand some of the frustrations of dealing with a "hacker language" like PHP, though I think the development community should maybe be a bit more patient with relatively new languages. PHP 5 seems to make a bit more sense, and things like WASP are attempting to drive consistency and proper design/architecture.
Also I don't think PHP is the only language that can be criticised for its "bolting on" of OOP 
king game (http://www.kinggame.org) wrote:
If you hate PHP what do you use then..and why are you still using PHP?
Keith (http://keithdevens.com/) wrote:
Thought I explained this above...
Feel free to post a comment below. Please see my comment policy.
Formatting Rules (No HTML):
Generated in about 0.215s.
(Used 8 db queries)

THANK YOU! I had the weirdest bug in an XML parsing class I wrote recently: for some reason, calls to update and check a property of the class just weren't working. I spent 2 days pulling my hair out about it before cludging it with a global variable (ugh) and moving on. I've just added the & to the $this in my xml_set_element_handler calls and now it works fine.
I am so looking forward to PHP5.