KBD

Keith Devens .com

Thursday, March 18, 2010 Flag waving
That is because you crazy! – Ikea

Archive: December 12, 2004

← December 11, 2004December 13, 2004 →

Daily link icon Sunday, December 12, 2004

  1. Power Line: Intel "Reform": Better Than We Thought?

       (0) Tags: [Opinions/Politics]
  2. Interest and Inflation Free Money (to read), via Adam (his del.icio.us links).

       (1)
  3. NewsForge | Linux needs better network file systems (to read), via Adam, who works for Google, which is supposed to have a revolutionary network filesystem that works on Linux. Too bad Adam probably can't talk about it. But, I just noticed there's a paper about it available.

       (3) Tags: [Programming]

Mixins in PHP (Or, I hate PHP volume 2)

For my Formation library what I really, really wanted was some way to do mixins in PHP. PHP doesn't support mixins or multiple inheritance natively even in PHP 5. But, I came across this post by whytheluckystiff over at Advogato from over two years ago where he tries to fake it (it turns out I blogged that link back then but had forgotten about it).

Through the comments on that post I found out about PHP's object aggregation functions. It turns out that does exactly what I need -- it simply stuffs all the methods in a given class into an existing object. Hence, a runtime, instance mixin. Literally, exactly what I needed. The only thing I would have liked is if the constructor for the mixin class could have been called upon mixing, but I don't think even Ruby does that for mixins.

However, when I checked out the documentation for the feature it had a big EXPERIMENTAL warning on it. I wouldn't want to use the feature in a library if it's not stable. So, I went looking around to see who to ask, and started poking around the dev mailing list. I searched for "aggregate" and found some references to bugs. So, I searched the bug db to see what it said there (incidentally, why don't they have the year of the bug report or its annotations listed anywhere??), and it turns out object aggregation isn't supported in PHP 5.

Have I mentioned I hate PHP? They added, but then took away exactly the feature I wanted. Now, because there's no multiple inheritance (even in PHP 5) -- which wouldn't do exactly what I want anyway -- I have to go back to manually creating a wrapper class that manually wraps all the methods in the wrapped class, and then you have to create an instance of that object separately and pass it an instance of the first class, etc. Is there any alternative?

Yet again, the PHP developers deprecate (with warnings!) or completely remove a feature without providing an acceptible alternative. How frustrating.


Addendum: To show how aggregate worked, here's some test code I whipped up:

<?php
class Foo{
    function 
testFoo(){
        echo 
"testFoo";
    }
}
class 
Bar{
    function 
testBar(){
        echo 
"testBar";
    }
}

$f = &new Foo();
aggregate($f'Bar');
$f->testFoo();
$f->testBar();
?>

Which prints "testFootestBar".

  1. Testing a change to my Formation library and my weblog software.

       (5) Tags: [This website]
  2. Wired 12.12: Roads Gone Wild. Interesting article about the psychology of road design. Via Matt. Incidentally, I'm a big fan of circles myself.

       (0)
  3. Koldark's Komputer World:: Camera Takes Picures of Amazing Detail. Impressive.

       (0)
  4. Little children scare the bejeezus out of me. That's all.

       (1) Tags: [Personal]
  5. perl.com: The Evolution of ePayment Services at UB - uses Inline::Java! It's magic!

       (0) Tags: [Programming]
← December 11, 2004December 13, 2004 →
March 2010
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 2 posts

Recent comments XML

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.05s.

(Used 7 db queries)