Archive

Archive for the ‘Daydreaming’ Category

Properties in PHP

January 1st, 2009 2 comments

A while ago Dynom from #php_bnl pointed me to an interesting entry on the PHP 5.3 wiki page. In the “Future PHP releases” sections there’s an entry called “29. “real” properties with attached getters and setters”. Personally I can’t wait for this. Hopefully it will look something like ActionScript 3′s properties:

<?php
class Bar
{
    private $_foo = 'foo';

    public function get foo()
    {
        return $this->_foo;
    }

    public function set foo($fooString)
    {
        $this->_foo = $fooString;
    }
}

$bar = new Bar();
$bar->foo = 'baz';
echo $bar->foo; // prints baz
Categories: Daydreaming, PHP Tags: