<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Enums in PHP</title>
	<atom:link href="http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html</link>
	<description>Ramblings of a Geek</description>
	<lastBuildDate>Sat, 26 Mar 2011 18:54:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: zanshine</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/comment-page-1#comment-856</link>
		<dc:creator>zanshine</dc:creator>
		<pubDate>Thu, 21 Oct 2010 09:05:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=383#comment-856</guid>
		<description>In the last comment, a part of the usage code have been eaten ...

So, here it is, without the nasty php open tag ;0) :

Usage: (@see usage.php, or unit tests for more details)
----------------------------------------

    //require the library
    require_once __DIR__ . &#039;/src/Enum.func.php&#039;;

    //if you don&#039;t have a cache directory, create one
    @mkdir(__DIR__ . &#039;/cache&#039;);
    EnumGenerator::setDefaultCachedClassesDir(__DIR__ . &#039;/cache&#039;);
    
    //Class definition is evaluated on the fly:
    Enum(&#039;FruitsEnum&#039;, array(&#039;apple&#039; , &#039;orange&#039; , &#039;rasberry&#039; , &#039;bannana&#039;));
    
    //Class definition is cached in the cache directory for later usage:
    Enum(&#039;CachedFruitsEnum&#039;, array(&#039;apple&#039; , &#039;orange&#039; , &#039;rasberry&#039; , &#039;bannana&#039;), &#039;\my\company\name\space&#039;, true);
    
    echo &#039;FruitsEnum::APPLE() == FruitsEnum::APPLE(): &#039;;
    var_dump(FruitsEnum::APPLE() == FruitsEnum::APPLE()) . &quot;\n&quot;;
    
    echo &#039;FruitsEnum::APPLE() == FruitsEnum::ORANGE(): &#039;;
    var_dump(FruitsEnum::APPLE() == FruitsEnum::ORANGE()) . &quot;\n&quot;;
    
    echo &#039;FruitsEnum::APPLE() instanceof Enum: &#039;;
    var_dump(FruitsEnum::APPLE() instanceof Enum) . &quot;\n&quot;;
    
    echo &#039;FruitsEnum::APPLE() instanceof FruitsEnum: &#039;;
    var_dump(FruitsEnum::APPLE() instanceof FruitsEnum) . &quot;\n&quot;;
    
    echo &quot;-&gt;getName()\n&quot;;
    foreach (FruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getName() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getValue()\n&quot;;
    foreach (FruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getValue() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getOrdinal()\n&quot;;
    foreach (CachedFruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getOrdinal() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getBinary()\n&quot;;
    foreach (CachedFruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getBinary() . &quot;\n&quot;;
    }

Output:
-------

    FruitsEnum::APPLE() == FruitsEnum::APPLE(): bool(true)
    FruitsEnum::APPLE() == FruitsEnum::ORANGE(): bool(false)
    FruitsEnum::APPLE() instanceof Enum: bool(true)
    FruitsEnum::APPLE() instanceof FruitsEnum: bool(true)
    -&gt;getName()
      APPLE
      ORANGE
      RASBERRY
      BANNANA
    -&gt;getValue()
      apple
      orange
      rasberry
      bannana
    -&gt;getValue() when values have been specified
      pig
      dog
      cat
      bird
    -&gt;getOrdinal()
      1
      2
      3
      4
    -&gt;getBinary()
      1
      2
      4
      8</description>
		<content:encoded><![CDATA[<p>In the last comment, a part of the usage code have been eaten &#8230;</p>
<p>So, here it is, without the nasty php open tag ;0) :</p>
<p>Usage: (@see usage.php, or unit tests for more details)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>    //require the library<br />
    require_once __DIR__ . &#8216;/src/Enum.func.php&#8217;;</p>
<p>    //if you don&#8217;t have a cache directory, create one<br />
    @mkdir(__DIR__ . &#8216;/cache&#8217;);<br />
    EnumGenerator::setDefaultCachedClassesDir(__DIR__ . &#8216;/cache&#8217;);</p>
<p>    //Class definition is evaluated on the fly:<br />
    Enum(&#8216;FruitsEnum&#8217;, array(&#8216;apple&#8217; , &#8216;orange&#8217; , &#8216;rasberry&#8217; , &#8216;bannana&#8217;));</p>
<p>    //Class definition is cached in the cache directory for later usage:<br />
    Enum(&#8216;CachedFruitsEnum&#8217;, array(&#8216;apple&#8217; , &#8216;orange&#8217; , &#8216;rasberry&#8217; , &#8216;bannana&#8217;), &#8216;\my\company\name\space&#8217;, true);</p>
<p>    echo &#8216;FruitsEnum::APPLE() == FruitsEnum::APPLE(): &#8216;;<br />
    var_dump(FruitsEnum::APPLE() == FruitsEnum::APPLE()) . &#8220;\n&#8221;;</p>
<p>    echo &#8216;FruitsEnum::APPLE() == FruitsEnum::ORANGE(): &#8216;;<br />
    var_dump(FruitsEnum::APPLE() == FruitsEnum::ORANGE()) . &#8220;\n&#8221;;</p>
<p>    echo &#8216;FruitsEnum::APPLE() instanceof Enum: &#8216;;<br />
    var_dump(FruitsEnum::APPLE() instanceof Enum) . &#8220;\n&#8221;;</p>
<p>    echo &#8216;FruitsEnum::APPLE() instanceof FruitsEnum: &#8216;;<br />
    var_dump(FruitsEnum::APPLE() instanceof FruitsEnum) . &#8220;\n&#8221;;</p>
<p>    echo &#8220;-&gt;getName()\n&#8221;;<br />
    foreach (FruitsEnum::iterator() as $enum)<br />
    {<br />
      echo &#8221;  &#8221; . $enum-&gt;getName() . &#8220;\n&#8221;;<br />
    }</p>
<p>    echo &#8220;-&gt;getValue()\n&#8221;;<br />
    foreach (FruitsEnum::iterator() as $enum)<br />
    {<br />
      echo &#8221;  &#8221; . $enum-&gt;getValue() . &#8220;\n&#8221;;<br />
    }</p>
<p>    echo &#8220;-&gt;getOrdinal()\n&#8221;;<br />
    foreach (CachedFruitsEnum::iterator() as $enum)<br />
    {<br />
      echo &#8221;  &#8221; . $enum-&gt;getOrdinal() . &#8220;\n&#8221;;<br />
    }</p>
<p>    echo &#8220;-&gt;getBinary()\n&#8221;;<br />
    foreach (CachedFruitsEnum::iterator() as $enum)<br />
    {<br />
      echo &#8221;  &#8221; . $enum-&gt;getBinary() . &#8220;\n&#8221;;<br />
    }</p>
<p>Output:<br />
&#8212;&#8212;-</p>
<p>    FruitsEnum::APPLE() == FruitsEnum::APPLE(): bool(true)<br />
    FruitsEnum::APPLE() == FruitsEnum::ORANGE(): bool(false)<br />
    FruitsEnum::APPLE() instanceof Enum: bool(true)<br />
    FruitsEnum::APPLE() instanceof FruitsEnum: bool(true)<br />
    -&gt;getName()<br />
      APPLE<br />
      ORANGE<br />
      RASBERRY<br />
      BANNANA<br />
    -&gt;getValue()<br />
      apple<br />
      orange<br />
      rasberry<br />
      bannana<br />
    -&gt;getValue() when values have been specified<br />
      pig<br />
      dog<br />
      cat<br />
      bird<br />
    -&gt;getOrdinal()<br />
      1<br />
      2<br />
      3<br />
      4<br />
    -&gt;getBinary()<br />
      1<br />
      2<br />
      4<br />
      8</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: zanshine</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/comment-page-1#comment-855</link>
		<dc:creator>zanshine</dc:creator>
		<pubDate>Thu, 21 Oct 2010 09:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=383#comment-855</guid>
		<description>Here is a github library for handling type-safe enumerations in php:

This library handle classes generation, classes caching and it implements the Type Safe Enumeration design pattern, with several helper methods for dealing with enums, like retrieving an ordinal for enums sorting, or retrieving a binary value, for enums combinations.

The generated code use a plain old php template file, which is also configurable, so you can provide your own template.

It is full test covered with phpunit.

&lt;a href=&quot;http://github.com/zanshine/php-enums&quot; rel=&quot;nofollow&quot;&gt;php-enums on github (feel free to fork)&lt;/a&gt;


Usage: (@see usage.php, or unit tests for more details)
----------------------------------------


   &lt;code&gt; getName()\n&quot;;
    foreach (FruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getName() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getValue()\n&quot;;
    foreach (FruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getValue() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getOrdinal()\n&quot;;
    foreach (CachedFruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getOrdinal() . &quot;\n&quot;;
    }
    
    echo &quot;-&gt;getBinary()\n&quot;;
    foreach (CachedFruitsEnum::iterator() as $enum)
    {
      echo &quot;  &quot; . $enum-&gt;getBinary() . &quot;\n&quot;;
    }

Output:
-------

    FruitsEnum::APPLE() == FruitsEnum::APPLE(): bool(true)
    FruitsEnum::APPLE() == FruitsEnum::ORANGE(): bool(false)
    FruitsEnum::APPLE() instanceof Enum: bool(true)
    FruitsEnum::APPLE() instanceof FruitsEnum: bool(true)
    -&gt;getName()
      APPLE
      ORANGE
      RASBERRY
      BANNANA
    -&gt;getValue()
      apple
      orange
      rasberry
      bannana
    -&gt;getValue() when values have been specified
      pig
      dog
      cat
      bird
    -&gt;getOrdinal()
      1
      2
      3
      4
    -&gt;getBinary()
      1
      2
      4
      8&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Here is a github library for handling type-safe enumerations in php:</p>
<p>This library handle classes generation, classes caching and it implements the Type Safe Enumeration design pattern, with several helper methods for dealing with enums, like retrieving an ordinal for enums sorting, or retrieving a binary value, for enums combinations.</p>
<p>The generated code use a plain old php template file, which is also configurable, so you can provide your own template.</p>
<p>It is full test covered with phpunit.</p>
<p><a href="http://github.com/zanshine/php-enums" rel="nofollow">php-enums on github (feel free to fork)</a></p>
<p>Usage: (@see usage.php, or unit tests for more details)<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>   <code> getName()\n";<br />
    foreach (FruitsEnum::iterator() as $enum)<br />
    {<br />
      echo "  " . $enum-&gt;getName() . "\n";<br />
    }</p>
<p>    echo "-&gt;getValue()\n";<br />
    foreach (FruitsEnum::iterator() as $enum)<br />
    {<br />
      echo "  " . $enum-&gt;getValue() . "\n";<br />
    }</p>
<p>    echo "-&gt;getOrdinal()\n";<br />
    foreach (CachedFruitsEnum::iterator() as $enum)<br />
    {<br />
      echo "  " . $enum-&gt;getOrdinal() . "\n";<br />
    }</p>
<p>    echo "-&gt;getBinary()\n";<br />
    foreach (CachedFruitsEnum::iterator() as $enum)<br />
    {<br />
      echo "  " . $enum-&gt;getBinary() . "\n";<br />
    }</p>
<p>Output:<br />
-------</p>
<p>    FruitsEnum::APPLE() == FruitsEnum::APPLE(): bool(true)<br />
    FruitsEnum::APPLE() == FruitsEnum::ORANGE(): bool(false)<br />
    FruitsEnum::APPLE() instanceof Enum: bool(true)<br />
    FruitsEnum::APPLE() instanceof FruitsEnum: bool(true)<br />
    -&gt;getName()<br />
      APPLE<br />
      ORANGE<br />
      RASBERRY<br />
      BANNANA<br />
    -&gt;getValue()<br />
      apple<br />
      orange<br />
      rasberry<br />
      bannana<br />
    -&gt;getValue() when values have been specified<br />
      pig<br />
      dog<br />
      cat<br />
      bird<br />
    -&gt;getOrdinal()<br />
      1<br />
      2<br />
      3<br />
      4<br />
    -&gt;getBinary()<br />
      1<br />
      2<br />
      4<br />
      8</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brainsick Patterns &#8212; No Code Relation &#187; Article &#187; Enumerations in PHP, um, OK</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/comment-page-1#comment-121</link>
		<dc:creator>Brainsick Patterns &#8212; No Code Relation &#187; Article &#187; Enumerations in PHP, um, OK</dc:creator>
		<pubDate>Tue, 27 Jan 2009 10:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=383#comment-121</guid>
		<description>[...] http://www.jeremyjohnstone.com/blog/archives/2008/10/05/enums-in-php/#more-383 [...]</description>
		<content:encoded><![CDATA[<p>[...] <a href="http://www.jeremyjohnstone.com/blog/archives/2008/10/05/enums-in-php/#more-383" rel="nofollow">http://www.jeremyjohnstone.com/blog/archives/2008/10/05/enums-in-php/#more-383</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mirin blog</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/comment-page-1#comment-122</link>
		<dc:creator>Mirin blog</dc:creator>
		<pubDate>Tue, 04 Nov 2008 22:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=383#comment-122</guid>
		<description>&lt;strong&gt;Enum v PHP...&lt;/strong&gt;

Jedna z věcí, která v PHP chybí je podpora výčtového typu - enum. Je to vlastně množina konstant - enumerátorů, každá má svůj identifikátor. Proměnná takového výčtového typu pak nabývá jednu z konstant. Bez výčtového typu se ...</description>
		<content:encoded><![CDATA[<p><strong>Enum v PHP&#8230;</strong></p>
<p>Jedna z věcí, která v PHP chybí je podpora výčtového typu &#8211; enum. Je to vlastně množina konstant &#8211; enumerátorů, každá má svůj identifikátor. Proměnná takového výčtového typu pak nabývá jednu z konstant. Bez výčtového typu se &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Johnstone&#8217;s Blog: Enums in PHP : Dragonfly Networks</title>
		<link>http://www.jeremyjohnstone.com/blog/2008-10-05-enums-in-php.html/comment-page-1#comment-120</link>
		<dc:creator>Jeremy Johnstone&#8217;s Blog: Enums in PHP : Dragonfly Networks</dc:creator>
		<pubDate>Tue, 07 Oct 2008 10:25:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremyjohnstone.com/blog/?p=383#comment-120</guid>
		<description>[...] this new post Jeremy Johnstone looks at creating a class to add that&#8217;s missing from the basic datatype set [...]</description>
		<content:encoded><![CDATA[<p>[...] this new post Jeremy Johnstone looks at creating a class to add that&#8217;s missing from the basic datatype set [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

