Re: [PHP] Beginner Tutorials for using CLASSES in PHP4



On Tue, 2007-10-09 at 09:12 -0400, Nathan Nobbe wrote:
On 10/7/07, Robert Cummings <robert@xxxxxxxxxxxxx> 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!
............................................................
.


Quantcast