Hey SO community,
I saw here: http://www.mustap.com/phpzone_post_203_setter-and-getter an argument for using
a type of property handling common to C#, that is:
If in C#, you can define a class like this:
public class Person
{
private string _name;
public string Name
{
get{ return _name; }
set{ _name = value; }
}
}
then why is it wise or not to define a similar property in php like this:
public class Person
{
private var $name;
public function Name()
{
if(func_num_args() == 0) { return $this->name; }
else {$this->name = func_get_arg(0); }
}
}
IMO, that doesn’t look clean in PHP. It’s like you’re trying to jam the C# way into PHP because you think it’s a nice feature of C#.
I see it as: In PHP, you’re making a single function for doing two completely different things, which doesn’t make sense. Meanwhile, in C#, it is single property, which is designed to be a single point of access for an object to be set/retrieved.