Re: Attributes vs. Accessors
| From: | Stut | Date: | Mon, 25 Aug 2008 12:40:27 +0000 |
| Subject: | Re: Attributes vs. Accessors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-278653@lists.php.net to get a copy of this message | ||
On 25 Aug 2008, at 13:32, Philip Thompson wrote:
Curious. Which do you prefer and why? <?php class Hello { public $hi; function __construct () {If it's a public member variable there is no need for plain accessor methods - they add no value. I feel the same about private variables with plain get and set accessors, there's just no point unless the accessors are doing more than setting and getting the internal variable. -Stut -- http://stut.net/$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?