On 3/28/06, Joe Henry <[EMAIL PROTECTED]> wrote:
> On Tuesday 28 March 2006 1:12 pm, Jochem Maas wrote:
> > <?php
> >
> > class Foo
> > {
> >       private $foo = 'foo';
> >
> >       function __get($k)
> >       {
> >               if (isset($this->{$k})) {
> >                       return $this->{$k};
> >               }
> >
> >               throw new Exception("non existing property!");
> >       }
> >
> >       function __set($k, $v)
> >       {
> >               if (isset($this->{$k})) {
> >                       $this->{$k} = $v;
> >                       return;
> >               }
> >
> >               throw new Exception("non existing property!");
> >       }
> > }
> >
> > $f = new Foo;
> > echo $f->foo,"\n";
> > $f->foo = "bar";
> > echo $f->foo,"\n";
>
> Maybe I'm wrong, but I thought you couldn't use the  "$f->foo" to access
> private variables from outside a class?

I think he means:

echo $f->__get('foo');
$f->__set('foo', 'bar');
echo $f->__get('foo');

---
foo
bar

If you want to validate input, you then have to have a block of nested
conditionals if your validation expressions vary.


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to