Attributes vs. Accessors

From: Date: Mon, 25 Aug 2008 12:32:11 +0000
Subject: Attributes vs. Accessors
Groups: php.general 
Request: Send a blank email to php-general+get-278651@lists.php.net to get a copy of this message
Hi all. Curious. Which do you prefer and why? <?php class Hello {
    public $hi;
    function __construct () {
        $this->hi = 'Well Hello There!';
    }
    function hi () {
        return $this->hi;
    }
} $hello = new Hello (); // Access the value this way... echo $hello->hi; // or the accessor... echo $hello->hi(); ?> For publicly-declared variables, do you access the attribute directly or use an accessor? ~Philip

« previous php.general (#278651) next »