I've noticed this style of code a lot in frameworks like Symfony and Magento 2 (which is based on Symfony):
<?php
class Foo
{
protected $foo;
# construct function - not needed for question
public function getFoo()
{
return $this->foo;
}
}
Which makes things easier to pick up in terms of get/set/unset but is there any actual advantage over using public vars?
<?php
class Foo
{
public $foo;
}
It seems the latter has fewer lines but less obvious flexibility.
What are the advantages/disadvantages to each method and when should I use one over the other?