Home > Daydreaming, PHP > Properties in PHP

Properties in PHP

January 1st, 2009 Leave a comment Go to 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:
  1. Reno
    February 2nd, 2009 at 23:27 | #1

    Actually i would prefer the C# notation:

    public function foo(){
    get{ $this->foo = value; }
    set{ return $this->foo; }
    }

  2. Reno
    February 2nd, 2009 at 23:28 | #2

    @Reno
    of course we’ll have to switch the get and set property in previous code sample

  1. January 14th, 2009 at 11:47 | #1