News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Felix Geisendorfer's Blog:
Assert the yummyness of your cake
October 25, 2007 @ 12:16:00

Felix Geisendorfer has posted an addition to his previous look at exceptions in CakePHP with a modification that uses assertions instead of an if to check the value of a variable.

I suddenly remembered what assertions are and how they could make my code more readable, while making it shorter. I took a quick look at PHP's assert function, but decided that I don't like it. [...] What I ended up doing was basically to create a class called Assert, and abuse it as a name-space for a whole bunch of useful assertion functions.

He includes two examples of how this new class would look, checking to see if a value is empty and to see if a task ID exists in a given value. The code for the assertion class is also included and has methods for checking things like "not empty", "equals to", "is not numeric" and "is an object". And, no, it's not CakePHP specific, so you could take it an use it anywhere.

1 comment voice your opinion now!
cakephp assertion class exception addition cakephp assertion class exception addition


blog comments powered by Disqus

Similar Posts

Andrei Zmievski's Blog: All the Little Pieces, or TextIterator in PHP 6

DevShed: Throwing Basic Exceptions When Auto Loading Classes in PHP 5

DevShed: Using Introspective Methods with the DirectoryIterator Class in PHP 5

Daniel Krook's Blog: Technologies of the day: CakePHP & CodeIgniter

Matt Curry's Blog:CakePHP Status Dashboard - Everything You Need To Know About Your App On One Page


Community Events

Don't see your event here?
Let us know!


extension laravel interview series security framework library community unittest api introduction symfony threedevsandamaybe laravel5 podcast opinion release voicesoftheelephpant language version

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework