KBD

Keith Devens .com

Thursday, December 4, 2008 Flag waving
"I am a leaf on the wind. Watch how I soar." – 'Wash' (Serenity, 2005)
← Freudian slip on Fox newsHow to interview a programmer →

Daily link icon Monday, February 24, 2003

God I hate PHP

PHP is one of the worst languages in use today. It's OO is so badly broken that I've been swearing all night at it. At one point tonight I thought what I've been trying to do would actually be much easier in Java!

Objects keep getting copied when I don't want them to, and I spend so long staring at it trying to figure out where that is. Some of my code even looks like this:

$p = &new StParagraphRecognizer($this);
$b = &new StBlockquoteRecognizer($this);
$t = &new StTextRecognizer($this);

$this->recognizers = array(
ST_PARA => &$p,
ST_BLOCKQUOTE => &$b,
ST_TEXT => &$t
);

just to avoid making copies, because you can't say something like ST_PARA => &new StParagraphRecognizer($this). Damn you PHP.

Update (2/25): It turns out (via a comment on the appropriate page in the PHP manual) that if you have your constructor always return a reference you can avoid having to do this. I haven't verified that this works, but it seems like it would. It doesn't change the fact that PHP's OO is fundamentally broken. In PHP 5 (with the Zend engine v2) PHP's OO will be more "normal" (i.e. more like Java), where objects have reference (pointer) semantics by default, and you have to copy explicitly (there're also other nice things built in).

After reading this, I'm wondering if I could find a host that has good support for Python, and switch over to that. There are lots of PHP-like solutions in Python (that link is just one among many). I don't know how they compare to PHP speed-wise, but anyway...

Update: It turns out there's a page in the manual that refers to this specific problem.

← Freudian slip on Fox newsHow to interview a programmer →

Comments XML gif

PeterV (http://poorbuthappy.com/ease) wrote:

Of course PHP's objects are fundamentally broken. I'm surprised you didn't know that. PHP is not a toy language, it just doesn't do objects well. Yet.

∴ PeterV | 9-Mar-2003 8:30pm est | http://poorbuthappy.com/ease | #1522

Keith (http://www.keithdevens.com/) wrote:

Well, I knew that they were broken, but I never actually ran into the brokenness much in practice because I stayed away from using objects in PHP. The toy language comment was maybe a little over half serious. The rest was just anger Smiley I mean, objects are a pretty major part of any language (except C), and for the semantics of that to be majorly broken is a big deal. So, I think the toy language comment is at least partially justified.

Keith | 9-Mar-2003 11:24pm est | http://www.keithdevens.com/ | #1523

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



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

Recent comments XML

Girls, please don't get breast implants

I have 34 A breast but at 22 years​old they seem to be growing again​which ...

76.64.120.153: Dec 3, 10:00am

Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Generated in about 0.191s.

(Used 8 db queries)

mobile phone