<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Mon, 20 May 2013 11:14:54 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Lee Davis' Blog: The enum conundrum]]></title>
      <guid>http://www.phpdeveloper.org/news/18192</guid>
      <link>http://www.phpdeveloper.org/news/18192</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Lee Davis</i> describes <a href="http://www.duckheads.co.uk/the-enum-conundrum/286">the enum conundrum</a> - what's the right solution for effectively using ENUM-type fields in your data?
</p>
<blockquote>
So a user signs up and I want to store a status that reflects their account, or at least an identifier representing that status. Their account could be active, disabled (temporarily), pending approval or maybe deleted. Should I use an enum? <a href="http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/">I've heard they're evil</a>. Maybe having a reference table with statuses would be better? But now I have to manage a separate table just for that one snippet of data, is that overkill? Could I maybe use that status table for other entities? Or, could I instead just use an integer and reference it on the code level? What is the right solution?
</blockquote>
<p>
He presents three of the most common situations he's seen for people using enums in the application:
</p>
<ul>
<li>"I used enums all over the place" (maintenance between code and DB values)
<li>"use a reference table"
<li>"I could use a class constant to represent the enum" (enforced in the app)
</ul>
<p>
Of the three, he suggests the third as the option with the most advantages. Not only does it make it simpler to get the allowed values for the field, but you're also more flexible in the kinds of validation you can do on the values.
</p>]]></description>
      <pubDate>Fri, 06 Jul 2012 11:56:52 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Mike Purcell's Blog: PHPUnit - Constant Already Defined - -process-isolation]]></title>
      <guid>http://www.phpdeveloper.org/news/18056</guid>
      <link>http://www.phpdeveloper.org/news/18056</link>
      <description><![CDATA[<p>
In <a href="http://melikedev.com/2012/06/06/phpunit-constant-already-defined-process-isolation/">this new post</a> from <i>Mike Purcell</i> shares a solution to an error he came across in his unit testing - a "Constant already defined" message - and how he fixed it.
</p>
<blockquote>
When upgrading the unit tests I had no problem, it was only when I was trying to integrate into CruiseControl that this was happening. Well after some time, I finally figured out the issue was the "ant" command to execute the unit tests was passing the -process-isolation flag to phpunit.
</blockquote>
<p>
He found that when he called it with that flag, it was executed twice, resulting in the "already defined" message the second time. He fixed it by removing the extra flag. Another alternative is to wrap your constant definitions (and anything that dosen't need to be called/created again) in an "is defined" check.
</p>]]></description>
      <pubDate>Thu, 07 Jun 2012 08:43:25 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Rob Allen's Blog: A primer on PHP namespaces]]></title>
      <guid>http://www.phpdeveloper.org/news/17549</guid>
      <link>http://www.phpdeveloper.org/news/17549</link>
      <description><![CDATA[<p>
For those that either haven't worked much with PHP 5.3 in their applications (or just haven't gotten around to using the feature) <i>Rob Allen</i> has <a href="http://akrabat.com/php/a-primer-on-php-namespaces/">put together an introduction to namespaces</a> to guide you through some first steps and share some example usage.
</p>
<blockquote>
I know that there are a lot of posts now about namespaces in PHP 5.3. This is mine which is how I learnt how they work. [...] That is, namespaces allow us to: combine libraries with the same classnames, avoid very long classnames and organise our code easily. Note that namespaces do not just affect classes. They also affect functions and constants.
</blockquote>
<p>
He starts with the basic namespace definition (using the "namespace" keyword), shows how to import another namespace with "use" and the use of the __NAMESPACE__ constant to determine what namespace you're operating in. More information on namespaces can be found <a href="http://php.net/manual/en/language.namespaces.rationale.php">in the PHP manual</a>.
</p>]]></description>
      <pubDate>Thu, 16 Feb 2012 08:25:43 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Effects of Wrapping Code in Class Constructs]]></title>
      <guid>http://www.phpdeveloper.org/news/17320</guid>
      <link>http://www.phpdeveloper.org/news/17320</link>
      <description><![CDATA[<p>
DevShed has a new tutorial posted today looking to help you counteract the bad practice of <a href="http://www.devshed.com/c/a/PHP/PHP-Effects-of-Wrapping-Code-in-Class-Constructs/">wrapping procedural code in "class" constructs</a> and provide some useful suggestions of how to avoid it.
</p>
<blockquote>
Static helpers seem to be a great idea at first glance, as they're reusable components that don't require any kind of expensive instantiation for doing common tasks [...]. But the sad and unavoidable truth is in many cases they're simply wrappers for procedural code, which has been elegantly hidden behind a "class" construct. So what's wrong with this? Well, even in the most harmless situations, when you use a static helper that produces a deterministic output, you're actually throwing away the advantages that OOP provides.
</blockquote>
<p>
To illustrate, they create a basic validation class that can check for things like valid emails, float values, integers and URLs using PHP's <a href="http://php.net/filter_var">filter_var</a> function. They point out that the class is difficult to extend and that it is doing too many things to be correctly considered a "piece" of functionality. To correct the problem, they opt for a different approach - an abstract class acting as an interface to structure custom validators against. This provides set/get methods for things like the error message and value to evaluate. The implementation of the validators on top of this class is coming in the next part of the series.
</p>]]></description>
      <pubDate>Thu, 29 Dec 2011 10:06:58 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Brandon Savage's Blog: Custom Apps: Some Strategies For Easy Configuration Files]]></title>
      <guid>http://www.phpdeveloper.org/news/13229</guid>
      <link>http://www.phpdeveloper.org/news/13229</link>
      <description><![CDATA[<p>
In <a href="http://www.brandonsavage.net/custom-apps-some-strategies-for-easy-configuration-files/">this new post</a> to his blog today <i>Brandon Savage</i> looks at configuration options for PHP apps and gives some examples to help you get the thought process started for your development.
</p>
<blockquote>
One of the decisions that has to be made each time an application is written for distribution is how best to set up the configuration files. There are a number of different approaches taken to this: some opt to use the define() function and define constants, while others use large arrays. 
</blockquote>
<p>
He points out a few "overlooked options" that some developers might no consider when working with configuration files like class constants and ini files (which PHP can <a href="http://us.php.net/manual/en/function.parse-ini-file.php">parse natively</a>). A few code snippets are included to show examples of them in use.
</p>]]></description>
      <pubDate>Wed, 16 Sep 2009 07:59:02 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Paul Reinheimer's Blog: Memcached Constants - Lame Code]]></title>
      <guid>http://www.phpdeveloper.org/news/12716</guid>
      <link>http://www.phpdeveloper.org/news/12716</link>
      <description><![CDATA[<p>
If you've worked with memcached and have ever run into an error, you might get tossed a code, the value of the error's constant, rather than the actual constant name. <i>Paul Reinheimer</i> was seeing just that and decided to map out all of the constants in relation to their error codes for future reference.
</p>
<blockquote>
I was running into a few errors, and <a href="http://ca3.php.net/manual/en/memcached.getresultcode.php">getResultCode()</a> was obligingly returning the value of the constant, rather than the <a href="http://ca3.php.net/manual/en/memcached.constants.php">constant</a> itself. I had to look up what that value meant. For some reason I couldn't reflect the extension to get the constants and values thereof, so with some lame scraping you get the following.
</blockquote>
<p>
He's included the list in both a normal text format and as a PHP array that can be cut and pasted directly into a library.
</p>]]></description>
      <pubDate>Fri, 19 Jun 2009 10:27:26 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Joseph Crawford's Blog: MySpace PHP REST Library]]></title>
      <guid>http://www.phpdeveloper.org/news/12433</guid>
      <link>http://www.phpdeveloper.org/news/12433</link>
      <description><![CDATA[<p>
For those still looking to interface with <a href="http://myspace.com">MySpace</a>, <i>Joseph Crawford</i> has <a href="http://josephcrawford.com/2009/04/28/myspace-php-rest-library/">pointed out</a> an <a href="http://wiki.developer.myspace.com/index.php?title=Category:MDP_Libraries#Official_MySpace_REST_API_PHP_Library">official REST library</a> for PHP to connect with their API.
</p>
<blockquote>
Over the last few days I have been digging deep into the concepts of REST. I have been reading through my copy of <a href="http://www.amazon.com/RESTful-Web-Services-Leonard-Richardson/dp/0596529260/ref=sr_1_1?ie=UTF8&s=books&qid=1240926906&sr=8-1">RESTful Web Services</a>. Out of curiosity I searched <A href="http://josephcrawford.com/2008/09/30/google-releases-update-engine/">Google</a> for a "php REST library" and it turned up the <a href="http://wiki.developer.myspace.com/index.php?title=Category:MDP_Libraries#Official_MySpace_REST_API_PHP_Library">Official MySpace PHP REST Library</a>.
</blockquote>
<p>
He points out one interesting thing about it, though - it's like they started using an object-oriented design but build after making the classes with properties. No methods.
</p>
<blockquote>
Even if they were to choose to go the PHP 5 way I would highly suggest that they do not use classes as containers for constants, there is no need to do this. It is not using proper OOP methodologies. Why create an object that just holds 2 - 4 constant variables, these would be better suited for define() calls in my opinion.
</blockquote>]]></description>
      <pubDate>Thu, 30 Apr 2009 10:25:55 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Packt Publishing: PHP Magic Features]]></title>
      <guid>http://www.phpdeveloper.org/news/12335</guid>
      <link>http://www.phpdeveloper.org/news/12335</link>
      <description><![CDATA[<p>
Packt Publishing has <a href="http://www.packtpub.com/article/php-magic-features">posted a new article</a> from <i>Jani Hartikainen</i> about the "magic methods" that PHP comes with - methods, properties and constants really.
</p>
<blockquote>
Magic methods, which are class methods with specific names, are used to perform various specialized tasks. They are grouped into two: overloading methods and non-overloading methods. [...] Magic functions, which are similar to magic methods, but are just plain functions outside any class. [...] Magic constants, which are similar to constants in notation, but act more like "dynamic" constants. We'll also look at some practical examples of using some of these, and lastly we'll check out what new features PHP 5.3 is going to add.
</blockquote>
<p>
He looks at the various functions/methods and constants (like __clone, __toString), some of the overloading methods like __call, and magic constants like __FILE__ and __CLASS__. He wraps it up by briefly discussing what PHP 5.3 adds in - a few new magic methods and constants (but no functions).
</p>
]]></description>
      <pubDate>Tue, 14 Apr 2009 09:31:48 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHP in Action Blog: I want enums in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/10159</guid>
      <link>http://www.phpdeveloper.org/news/10159</link>
      <description><![CDATA[<blockquote>I want Enums in PHP</blockquote>
<p>
That's how <a href="http://www.reiersol.com/blog/index.php?op=ViewArticle&articleId=36&blogId=1">this new post</a> on the PHP in Action blog starts this morning. The one thing that he wants is enumeration support in PHP. He shows how it can currently come close with a "roles" system:
</p>
<blockquote>
Useful examples I've encountered in web programming are states or stages in a process and user roles. Another kind of example is one I used in PHP In Action: an authorization system with three fixed roles or categories of user: regular, webmaster and administrator.
</blockquote>
<p>
He sets up an example class that sets constants for the different access levels rather than just relying on strings to handle it (which, as he points out, could very easily be misspelled and not throw any kind of error) .
</p>]]></description>
      <pubDate>Mon, 12 May 2008 08:41:16 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Hasin Hayder's Blog: Web scrapping in a smart way, making a "Today in History" object in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/10063</guid>
      <link>http://www.phpdeveloper.org/news/10063</link>
      <description><![CDATA[<p>
<i>Hasin Hayder</i> has written up a <a href="http://hasin.wordpress.com/2008/04/29/web-scrapping-in-a-smart-way-making-a-today-in-history-object/">quick tutorial</a> for his blog that shows how to create your own "Today in History" page with details from <a href="http://www.scopesys.com/">Scopesys</a> pulled with a little web scraping.
</p>
<blockquote>
There are thousands of services available on web who are presenting interesting as well as education information which you can really integrate in your web page or make a nice widget and let others use them seamlessly with their content delivery platforms. In this article I am going to show you how you can make a nice Today-in-History widget with the help of the data provided in <a href="http://www.scopesys.com/">Scopesys</a>.
</blockquote>
<p>
He wisely recommends that you check one thing first about the content you're grabbing - the copyright it carries with it. This could get you into big trouble down the line depending on whose content it is. The actual script is pretty simple - he defines some constants as markers for where things start and stop in the HTML and then uses strpos to get the locations for his substr call to grab the segments.
</p>]]></description>
      <pubDate>Tue, 29 Apr 2008 10:27:41 -0500</pubDate>
    </item>
  </channel>
</rss>
