you're reading...


Version 5

If I didn’t know better I’d say that the PHP guys were taking a big lesson from .NET and C#.

Though I cringe everytime the documentation refers to class member variables as properties the changes in the latest version of PHP are enough to make me happy. I’ve already started to write some new code using the beta version, though I can’t test it remotely yet I have had some fun in writing a base class that lets me write .NET style properties.

I’ll even share some of my code.

class BaseObject 
    function __get( $name )
        $var = 'get' . $name;
        if( method_exists( $this, $var ) )
            return call_user_func( array( &$this, $var ) );
            return $this->$name;
    function __set( $name, $value )
        $var = 'set' . $name;
        if( method_exists( $this, $var ) )
            call_user_func( array( &$this, $var ), $value );
            $this->$name = $value;
class TestObject extends BaseObject
    private $foo;
$to = new TestObject;
$to->Foo = 5;
$to->Foo += 3;
echo $to->Foo;

Update: Yes, I know; the code needs more line breaks, but it seems that the WordPress Texturize feature isn’t very code friendly so I lost all of my nice line breaks from the original code. Oh well, I’ll work on it later.


About James

I am a Senior Developer/Consultant for InfoPlanIT, LLC. I previously spent over 7 years as a Product Manager for what eventually became ComponentOne, a division of GrapeCity. While there, I helped to create ActiveReports 7, GrapeCity ActiveAnalysis, and Data Dynamics Reports.


2 thoughts on “PHP 5

  1. Could also do with a bit more colour whilst youe at it :p

    Posted by Nnamdi | December 26, 2003, 12:05 am
  2. Good idea, I’ll see if I can hack something together to let me selectivly run parts of my post through the PHP Source to HTML thingy 🙂 That could play havoc on my color themes, but a few RegEx’s could fix that as well.

    Posted by James T. Johnson | December 26, 2003, 12:22 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: