PHP Classes

Suggestion: class constants

Recommend this page to a friend!

      Typesafe Enum  >  All threads  >  Suggestion: class constants  >  (Un) Subscribe thread alerts  
Subject:Suggestion: class constants
Summary:It could be useful to expose the enum values as class constants
Messages:2
Author:Martin Alterisio
Date:2010-04-02 01:00:50
Update:2010-04-02 14:30:29
 

 


  1. Suggestion: class constants   Reply   Report abuse  
Picture of Martin Alterisio Martin Alterisio - 2010-04-02 01:00:50
Just a suggestion, go the extra mile and provide the enumeration values as class constants. Using Suit::SPADES is more intuitive and readable than Suit::SPADES()

php.net/language.oop5.constants

  2. Re: Suggestion: class constants   Reply   Report abuse  
Picture of Fabian Schmengler Fabian Schmengler - 2010-04-02 14:30:29 - In reply to message 1 from Martin Alterisio
This was my first attempt but as far as I know PHP does not allow initialization of class constants with objects*, for this reason I chose class methods in the first place. If you have an idea to solve this, I'd be happy to hear about it. It should be possible with runkit but I don't know if I should rely on it.

*) at least something like this does not work:

class Suite
{
const SPADES = new Suite('SPADES');
}