News Feed
Jobs Feed
Sections




News Archive
Benjamin Eberlei's Blog:
Enums in PHP
September 01, 2009 @ 12:46:34

In a new post to his blog Benjamin Eberlei talks about enum data types in PHP and how the is getting close but still isn't quite there yet.

If you want to implement Enum behaviour with a simple string or int value you end up with having to validate the values at several different locations in the code rather than being able to strictly enforce the Enum structure by using typehints.

In an effort to try to help the situation he and a colleague came up with an abstract class MyEnum that uses the __toString method to do value checking. Code examples are included for the class and how to use it.

0 comments voice your opinion now!
enum splenum example code


blog comments powered by Disqus

Similar Posts

Fernando Bassani's Blog: Putting the PHP/Java Bridge to work - I

Johannes Schluter's Blog: Code and human languages

PHPImpact Blog: No need for set/get methods in Python

David Coallier's Blog: PHP Namespaces (Part 1: Basic usage & gotchas)

Mark Brady's Blog: Closures in PHP 5.3


Community Events











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


symfony2 interview conference introduction community example database development rest phpunit release functional usergroup testing framework series opinion language podcast zendframework2

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