On Mon, Aug 25, 2008 at 8:32 AM, Philip Thompson <[EMAIL PROTECTED]> wrote:
> 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
I access directly to avoid pointless method calls for reads. It'd be
nice if there were a way to define a public read-only mode, but in my
code it is more of a rule of thumb. I'm pretty strict on what gets
public visibility though.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php