note 89524 rejected from splenum.construct by thiago

From: Date: Thu, 12 Mar 2009 12:41:11 +0000
Subject: note 89524 rejected from splenum.construct by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151765@lists.php.net to get a copy of this message
Note Submitter: viigihabe at gmail dot com ---- This example above is a bit confusing, while in this example is no enum actually genereted. I was looking at it, and thought that there must be an other way, other conclusion. And I found that the constructor parameter, indicated as an integer value is only a half truth. I'm not the one who can make statement on this, but it seems that PHP treats constatnts whether they represent integer or string value as an integer. That gives the real opportunity to make Enum. As an example: class myFavorites extends splEnum { const HTML = 'html'; const XML = 'xml'; const PHP = 'php'; } function echoFavorite(myFavorites $favorite) { echo "My favorite is: " . $favorite; } echoFavorite(new myFavorites(myFavorites::PHP)); That thing makes sure that any literal or numeric value can be malformed by other developers or by yourself. Hope that snippet was useful.

« previous php.notes (#151765) next »