Re: Beginner Tutorials for using CLASSES in PHP4
| From: | Robert Cummings | Date: | Tue, 09 Oct 2007 15:29:53 +0000 |
| Subject: | Re: Beginner Tutorials for using CLASSES in PHP4 | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-262972@lists.php.net to get a copy of this message | ||
On Tue, 2007-10-09 at 09:12 -0400, Nathan Nobbe wrote:
> On 10/7/07, Robert Cummings <robert@interjinn.com> wrote:
>
> > Nothing brittle at all about PHP4 code. I can completely screw
> > up any PHP5 code you send my way too.
>
> ok;
> without modifying this class, set the value of $someInt to a value
> greater than
> 100 or less than 0.
>
> class TryToViolateEncapsulation {
> private $someInt = 0;
>
> public function getSomeInt() {
> return $this->someInt;
> }
>
> public function setSomeInt($someInt) {
> $success = false; // assume failure
> $someInt = (int) $someInt;
> if($this->isValid($someInt)) {
> $this->someInt = $someInt;
> $success = true;
> }
>
> return $success;
> }
>
> private function isValid($someInt) {
> $isValid = true;
> if($someInt < 0 || $someInt > 100) {
> $isValid = false;
> }
> return $isValid;
> }
> }
$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.
--
...........................................................
SwarmBuy.com - http://www.swarmbuy.com
Leveraging the buying power of the masses!
...........................................................