Re: Beginner Tutorials for using CLASSES in PHP4
| From: | Larry Garfield | Date: | Wed, 10 Oct 2007 00:54:52 +0000 |
| Subject: | Re: Beginner Tutorials for using CLASSES in PHP4 | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-263013@lists.php.net to get a copy of this message | ||
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. :-)
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.
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. :-)
--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson