Re: Beginner Tutorials for using CLASSES in PHP4
| From: | Nathan Nobbe | Date: | Wed, 10 Oct 2007 01:49:32 +0000 |
| Subject: | Re: Beginner Tutorials for using CLASSES in PHP4 | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263019@lists.php.net to get a copy of this message | ||
On 10/9/07, Larry Garfield <larry@garfieldtech.com> wrote:
>
> On Tuesday 09 October 2007, Robert Cummings wrote:
>
> > $sucker = new TryToViolateEncapsulation();
> > $sucker = (array)$sucker;
> >
> > $keys = array_keys( $sucker );
> > $sucker[reset( $keys )] = 500;
> >
> > $sucker = serialize( (object)$sucker );
> > $sucker = 'O:25:"TryToViolateEncapsulation"'.substr( $sucker, 14 );
> > $sucker = unserialize( $sucker );
> >
> > print_r( $sucker );
> >
> >
> >
> > Maybe next time you'll have a challenge for me ;) And don't whine about
> > how I achieved what I did.
> >
> > Cheers,
> > Rob.
>
> I've never actually thought of doing it that way, but I must say I find it
> an
> amusing method. :-)
i new rob would come up w/ something otherwise he wouldnt have made the
offer.
i tried to override the __sleep method to throw an exception but it had no
effect;
rob really knows php well.
That said, I stand by my earlier comment. Never use private
> variables. Ever.
> Use public or protected, but never private. Private makes them
> un-extensible
> to child classes. That's just flat out rude.
right; protected is only for variables that the child class would need
access to;
even children dont need access to all of their parents details.
i say; mark all member variables private and reduce the access as need be.
And really, there's FAR more interesting and useful pieces to OOP, PHP's
> style
> or otherwise, than PPP. Interfaces are useful. Being able to pass
> objects
> around to each other without performance or references dying is
> useful. And
> SPL is just plain cool. :-)
yes; SPL is really nice; though some more documentation would be great.
the articles online mostly cover basic usage examples.
-nathan