Según las necesidades es mejor que los atributos sean privados. También podría ser así:
Código PHP:
Ver original<?php
class Algo
{
private $_variable;
public function __construct($str)
{
$this->_variable = $str;
}
public function getVariable()
{
return $this->_variable;
}
}
$a = new Algo('Hola Mundo');
echo $a->getVariable(); //Hola Mundo