note 89524 added to splenum.construct

From: Date: Thu, 12 Mar 2009 12:12:00 +0000
Subject: note 89524 added to splenum.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-151763@lists.php.net to get a copy of this message
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. ---- Server IP: 203.121.145.220 Probable Submitter: 213.35.164.70 ---- Manual Page -- http://www.php.net/manual/en/splenum.construct.php Edit -- https://master.php.net/note/edit/89524 Del: integrated -- https://master.php.net/note/delete/89524/integrated Del: useless -- https://master.php.net/note/delete/89524/useless Del: bad code -- https://master.php.net/note/delete/89524/bad+code Del: spam -- https://master.php.net/note/delete/89524/spam Del: non-english -- https://master.php.net/note/delete/89524/non-english Del: in docs -- https://master.php.net/note/delete/89524/in+docs Del: other reasons-- https://master.php.net/note/delete/89524 Reject -- https://master.php.net/note/reject/89524 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151763) next »