Locking Down a PHP Object

"Controlling complexity is the essence of computer programming."

~Brian Kernigan

Today is Code Monkey Friday at StoryChuck

When programming in PHP one of the most annoying gotchas is when there's a typo in an object property that isn't readily apparent. Let's say you have a simple object as follows:


class Stupid {
public $Gotcha = 1;
}

And then you some code using this object:


$obj = new Stupid;
$obj->gotcha = 2;
... more code ...

The problem is that pesky lowercase 'g' in gotcha. In the...

 •  0 comments  •  flag
Share on Twitter
Published on March 23, 2012 11:26
No comments have been added yet.