News Feed
Sections




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

Jeremy Johnstone's Blog:
Enums in PHP
October 06, 2008 @ 07:56:08

In this new post Jeremy Johnstone looks at creating a class to add that's missing from the basic datatype set of the language - enums.

I stumbled across a blog post on how to implement Enums in PHP via userland code written by Jonathan Hohle. I liked the concept he had, but the implementation was a bit unappealing because it used eval() among other more minor issues. You shouldn't need to generate Enums at runtime, so I took that as a challenge to find a way to do it at compile time, thus making the code much more efficient.

His enums would support type hinting and would, ideally, be iterable. He gives the code he's worked up - a base class, another than extends it to make a basic enum structure and some handy changes to support comparisons. A few more changes (and a few other extended classes later) he has some pretty well functioning enums that can even bee iterated through.

0 comments voice your opinion now!
enum tutorial base datatype userland class


blog comments powered by Disqus

Similar Posts

PHPMac.com: Building and Installing Apache 2.2.2 and PHP 5.1.3 (or 5.1.4) on Mac OS X 10.4.6

Sameer Borate's Blog: Read the version of a PDF in PHP

HowTo Forge: Installing Lighttpd With PHP5 And MySQL Support On Fedora 7

Mohammed Berdai's Blog: How To Install PostgreSQL And phpPgAdmin Support In XAMPP

Zend Developer Zone: Using GnuPG with PHP


Community Events





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


deployment package tips api zendserver introduction interview community library release podcast framework opinion language install bugfix series version symfony laravel

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