Properties in PHP
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
Actually i would prefer the C# notation:
public function foo(){
get{ $this->foo = value; }
set{ return $this->foo; }
}
@Reno
of course we’ll have to switch the get and set property in previous code sample