News Feed
Sections




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

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

DevShed: Understanding Destructors in PHP 5

Padraic Brady's Blog: Zend Framework Blog Tutorial - Part 7: Authorisation with Zend_Acl & Styling

Kevin van Zonneveld's Blog: Convert anything to Tree Structures in PHP

David Goodwin's Blog: Book Review: Object-Orientated Programming with PHP5 (Hasin Hayder, Packt)

Matthew Weir O'Phinney's Blog: PHP globals for the OOP developer


Community Events





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


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

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