I know this is probably subjective but I read this optimization page from Google for PHP and they suggest use the variable property directly without the need of getters and
It depends on whether $name
is public or not. If it's not, you can't access/modify it directly. The trade off is exposing your class's internal data elements directly to integrators. This may be OK for some classes, but not for others.
For example, you wouldn't necessarily want others to be able to modify the price of a product directly in a Product
class.