KBD

Keith Devens .com

Sunday, September 7, 2008 Flag waving
A charlatan makes obscure what is clear; a thinker makes clear what is obscure. – Hugh Kingsmill

Archive: August 13, 2003

← August 12, 2003August 14, 2003 →

Daily link icon Wednesday, August 13, 2003

I hate PHP

I hate PHP... just hate it. Hate it hate it hate it.

The newest thing I've been dealing with is the idiotic call-time pass-by-reference deprecation. I've never heard the reasoning for the deprecation, and as far as I can tell, there isn't any. I should start keeping a list of all the things that become impossible without it...

  • You can't have a default argument in a function that's passed by reference: function ($foo, &$bar = NULL){} doesn't work, although it will in PHP 5. Great, make alternatives available before you deprecate features, assholes.
  • Want to append a reference to an array using array_unshift, array_push, etc.? array_unshift($array, &$value) is no good. The only solution for array_unshift is to create new arrays and manually shuffle everything around.
  • Want to allow a callback to be called using call_user_func and have its arguments passed by reference? You're out of luck again. The only solution is to wrap a reference to your argument in an array and pass that... and your callback functions have to be rewritten to take arrays.
  • Finally, the worst example, which has caused me to waste literally hours trying to fix it is this: I've been removing call-time pass-by-reference from my XML-RPC library, because it's deprecated and people keep getting error messages when using my library (which isn't good). So, I tried to remove call-time pass-by-reference stuff a long time ago when I started working on version 3. So now I started working on the XML parsing part of it, which happens to use xml_set_object. Check out the documentation for that... it uses this line: "xml_set_object($this->parser, &$this);" Which, of course... **IS DEPRECATED**

I'm so mad my head's going to explode... I've been trying very hard to avoid littering this post with four letter words. What this last example shows is that xml_set_object is completely useless without being able to pass an object reference in there, since typically you'll store instance data representing your XML data in that object, and if you don't pass $this by reference you'll wind up with copies all over the place, which is what was happening to me. I think the solution to this is to pass array(&$this, "callback") to xml_set_element_handler, so we'll see.

The last example should work in PHP 5 as well, since objects will be passed by reference and not by value (which was another damn huge design mistake in the first place). But they deprecated a feature, which causes everyone to get big ugly error messages (not even NOTICEs, but WARNINGs) under the default install, without providing any workarounds or replacements.

PHP is a horrid language that I never want to have to do any development with ever again. Unfortunately, there are really no alternatives available that are widely deployed on shared hosts.

References and pointers

I really think I'm beginning to dislike languages that don't have an explicit concept of a reference or a pointer. Copies get made when you don't want them, but you have no control over it. Often you wind up having to stick the data you want to take a reference to in an array (since arrays often get passed by reference in these types of languages) so you can get the same effect. It has other consequences as well. All the more reason why I'm looking forward to Perl 6, since Python, even though I dig it, is one of those languages that steals pointers from you. In fact, most of the languages that we're all stuck using do this, including Python, Java, and PHP.

It seems like most the time I spend tracking down bugs in PHP is spent trying to figure out where a copy is being made. Over and frickin over again - that's not a fun way to spend your time.

Class is over

Finally, my last summer course has ended, I did decently on the final, and now I can finally get myself back on track for everything I wanted to finish over the summer and everything I have to do before next semester starts.

← August 12, 2003August 14, 2003 →
September 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 7 posts

Recent comments XML

new⇒Trogdor tattoo!!

Oh, so cute, wowoowow....

Kathy Mead: Sep 7, 6:07am

new⇒I hate Norton Antivirus

Long long live AVG I love you!...

kevin sands: Sep 6, 7:31pm

I hate ASP.NET

CF, why pick that piece of trash?​Cold Confusion. Is it finally​really a OO...

ColdConfusion: Sep 5, 8:36pm

Maps of Iraq

This is for Linda, I will be​visiting that site some time in the​near futur...

Bob: Sep 5, 1:20pm

Girls, please don't get breast implants

Well alright I just read my above​comment and I wanted to add​this...I shou...

76.66.140.8: Sep 4, 7:31pm

Spider solitaire

I don't think the question was​necessarily if there are unbeatable​games.  ...

Jared: Sep 4, 12:44pm

Convert Pantone Colors to RGB and Hex - Color Conversion Chart

The colors on those website don't​seem to relate to the pantone data​we hav...

blah: Sep 3, 10:12am

Generated in about 0.062s.

(Used 7 db queries)

mobile phone