<?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>Fri, 24 May 2013 00:03:01 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Christopher Martinez: Static code analysis tools for PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19563</guid>
      <link>http://www.phpdeveloper.org/news/19563</link>
      <description><![CDATA[<p>
<I>Christopher Martinez</i> has a recent post to his site that covers some of the <a href="http://chrsm.org/2013/05/05/code-analysis-tools-for-php">static analysis tools available for PHP</a> including the PHP Mess Detector, PHP CodeSniffer and the PHP Analyzer.
</p>
<blockquote>
I believe in writing code that is easy to understand, easy to test, and easy to refactor. Yes, I realize that the statement above is pretty general and open to interpretation. Not everyone needs external tools to ensure quality in their code...but, I work on things from time to time that have absolutely no tests. [...] For whatever reason, this happens a lot more frequently in the PHP world. I'm guilty of not writing tests and checking how I write code, sometimes, too. Things are bright, though, for the PHP community - for quite some time now, we've had fantastic tools that assist us in writing better code. 
</blockquote>
<p>
He covers each of the tools, talks some about what they're good for and gives examples of their use, including output. He also talks some about the <a href="https://github.com/facebook/pfff">Pfff</a> set of tools created by Facebook. He also talks some about how these tools fit into his daily work as a part of his pre-commit hooks in git.
</p>
Link: http://chrsm.org/2013/05/05/code-analysis-tools-for-php]]></description>
      <pubDate>Wed, 08 May 2013 12:38:22 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Benjamin Eberlei: Traits are Static Access]]></title>
      <guid>http://www.phpdeveloper.org/news/19453</guid>
      <link>http://www.phpdeveloper.org/news/19453</link>
      <description><![CDATA[<p>
In a new post to his site <i>Benjamin Eberlei</i> shares an opinion about traits, noting that they're <a href="http://www.whitewashing.de/2013/04/12/traits_are_static_access.html">basically the same as static functionality</a> when it comes to several things like coupling, not being testable and being a "global state" container.
</p>
<blockquote>
I used to look forward to traits as a feature in PHP 5.4, but after discussions with Kore I came to the conclusion that traits are nothing else than static access in disguise. They actually lead to the exact same code smells. Familiar with the outcome of too much static use, we should reject traits as just another way of statically coupling your code to other classes.
</blockquote>
<p>
He includes some code examples showing traits in use in an example controller to handle a simple redirect. He points out at least six different issues with just this simple implementation. He rewrites it as "static" code to help prove his point. He comes to the conclusion that, much like static methods, traits should be avoided and instead aggregation should be favored.
</p>
Link: http://www.whitewashing.de/2013/04/12/traits_are_static_access.html]]></description>
      <pubDate>Fri, 12 Apr 2013 11:16:35 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[David Zentgraf: How Not To Kill Your Testability Using Statics]]></title>
      <guid>http://www.phpdeveloper.org/news/18847</guid>
      <link>http://www.phpdeveloper.org/news/18847</link>
      <description><![CDATA[<p>
If you've been around PHP for any length of time, you know about the <a href="http://php.net/static">static functionality</a> and keyword that the language offers. You might have used it in the past for a few things, but maybe you're not 100% sure of how to use it right. If this describes you, you should check out <a href="http://kunststube.net/static/">this article</a> from <i>David Zentgraf</i> for a great summary of their use and how to not kill the testability of your application by using them,
</p>
<blockquote>
"Class Oriented Programming" is what people do when they write classes which are all static methods and properties and are never once instantiated. I'll try to explain why this adds virtually nothing vis-a-vis procedural programming, what these people are really missing out on by ignoring objects and why, against all odds, statics don't automatically kill testability. While this article focuses on PHP, the concepts apply equally across many languages.
</blockquote>
<p>
He talks about code coupling, expectations when using static classes/methods and how it seems a little too similar to some of the procedural PHP we all started out writing. He ponts out that most static method calls are more like function calls than true OOP methods and that their dependencies are a bit more difficult to manage. He suggests that statics are really only good for one kind of thing - dealing with already static data and "utility methods" operating on given data.
</p>]]></description>
      <pubDate>Wed, 05 Dec 2012 11:57:33 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Reddit.com: Avoid static methods at all costs? (testability)]]></title>
      <guid>http://www.phpdeveloper.org/news/18523</guid>
      <link>http://www.phpdeveloper.org/news/18523</link>
      <description><![CDATA[<p>
On Reddit.com there's <a href="http://www.reddit.com/r/PHP/comments/10hank/avoid_static_methods_at_all_costs_testability/">a recent post</a> questioning the (recently) common saying that PHP developers should avoid static methods when concerned about testability:
</p>
<blockquote>
I get it: testing is important, and building your codebase in a manner that is easy to test should be a priority. However, sometimes I feel like I have to compromise on the elegance of my code in order to maintain testability. Cases where perhaps a static method makes sense, but end up having to perform some coding acrobatics in order to avoid it. Is this a common challenge, something many developers face and must balance between? Or am I misguided in how frequently static methods can be the most elegant solution (before taking testability into consideration)?
</blockquote>
<p>
<a href="http://www.reddit.com/r/PHP/comments/10hank/avoid_static_methods_at_all_costs_testability/#comments">Answers</a> point out a few things - that sometimes, state doesn't matter and static is okay or that they can be used if the instance they return is always exactly the same, never altered.
</p>]]></description>
      <pubDate>Wed, 26 Sep 2012 11:59:04 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Anthony Ferrara: Is Autoloading A Good Solution?]]></title>
      <guid>http://www.phpdeveloper.org/news/18255</guid>
      <link>http://www.phpdeveloper.org/news/18255</link>
      <description><![CDATA[<p>
In his <a href="http://blog.ircmaxell.com/2012/07/is-autoloading-good-solution.html">most recent post</a> <i>Anthony Ferrara</i> takes a look at autoloading - mostly asking the question of whether the problems it has really outweigh the benefits.
</p>
<blockquote>
The real problem that autoloaders solve is to load dependencies. [...] The normal logic that's used to justify autoloading over manual dependency loading in production is that it only loads the classes you need. Therefore you save the parsing costs of classes that you don't need. But surely that additional run-time loading has costs. So I decided to setup a test to see how expensive that additional run-time loading costs us, and to prove whether or not autoloading is worth it in production.
</blockquote>
<p>
He gives an example of the two methods - using the <a href="http://php.net/spl_autoload_register"> spl_autoload_register</a> method to define a loader and loading them with a defined file path instead. He found the autoloading version slower than the hard-coded (by quite a bit) but how, when the number of files is reduced, the performance gets much closer. He also briefly looks at two other pieces of file-related functionality: <a href="http://php.net/file_exists">file_exists</a> and <a href="http://php.net/require_once">require_once</a>.
</p>]]></description>
      <pubDate>Fri, 20 Jul 2012 15:56:30 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Nikita Popov's Blog: Scalar type hinting is harder than you think]]></title>
      <guid>http://www.phpdeveloper.org/news/17638</guid>
      <link>http://www.phpdeveloper.org/news/17638</link>
      <description><![CDATA[<p>
In <a href="http://nikic.github.com/2012/03/06/Scalar-type-hinting-is-harder-than-you-think">this new post</a> to his blog <i>Nikita</i> talks about scalar type hinting and why it's harder than most people think to accomplish.
</p>
<blockquote>
One of the features originally planned for PHP 5.4 was scalar type hinting. But as you know, they weren't included in the release. Recently the topic has come up again on the mailing list and there has been a hell lot of discussion about it. Yesterday ircmaxell published a <a href="http://blog.ircmaxell.com/2012/03/parameter-type-casting-in-php.html">blog post about his particular proposals</a>. The reactions on <a href="http://www.reddit.com/r/PHP/comments/qiniv/parameter_type_casting_in_php/">reddit</a> were mixed. On one hand it is clear that people do really want scalar type hints, on the other hand they didn't seem to like that particular proposal.
</blockquote>
<p>
He gets into some of the details of some of the current proposals and their problems like the strict versus loosely-typed nature of PHP and type hinting that was included but not enforced. One he does like, however, is one based on casting - how the variable ends up being cast rather than the specific type it is when it comes into the function/method. This one still has its flaws, so he suggests another method - weak type hints but with stricter input validation (without casting). He also briefly mentions something called "box based type hinting" that would allow users to define their own hinting rules.
</p>
<p>
Don't worry - code examples (pseudo-code obviously) <a href="http://nikic.github.com/2012/03/06/Scalar-type-hinting-is-harder-than-you-think">are included</a> for each of these proposals to help you understand the differences.
</p>]]></description>
      <pubDate>Wed, 07 Mar 2012 10:03:47 -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[Sebastian Bergmann's Blog: Using CLANG/scan-build for Static Analysis of the PHP Interpreter]]></title>
      <guid>http://www.phpdeveloper.org/news/17269</guid>
      <link>http://www.phpdeveloper.org/news/17269</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Sebastian Bergmann</i> takes a quick look at <a href="http://sebastian-bergmann.de/archives/916-Using-CLANGscan-build-for-Static-Analysis-of-the-PHP-Interpreter.html">using a static analyzer</a>, <a href="http://clang.llvm.org/">clang</a> and scan-build, to analyze the PHP interpreter (specifically during the compile process).
</p>
<blockquote>
I have been tinkering with <a href="http://clang.llvm.org/">CLANG</a>'s <a href="http://clang-analyzer.llvm.org/">static analyzer</a> lately. This post summarizes how I installed LLVM and CLANG and performed the analysis of a build of the PHP interpreter.
</blockquote>
<p>
He includes all the commands (unix-based) to get the clang tools/libraries installed in the correct places as well as what to add to your $PATH to get the "scan-build" command to work with the make and make install parts of the PHP compile process.
</p>]]></description>
      <pubDate>Fri, 16 Dec 2011 09:48:07 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Lorna Mitchell's Blog: PHP Static Analysis Tool Usage]]></title>
      <guid>http://www.phpdeveloper.org/news/16668</guid>
      <link>http://www.phpdeveloper.org/news/16668</link>
      <description><![CDATA[<p>
In an informal poll <i>Lorna Mitchell</i> recently asked fellow developers to weigh in on what static analysis tool they used on their code. She's <a href="http://www.lornajane.net/posts/2011/PHP-Static-Analysis-Tool-Usage">posted the results</a> to her blog today with one of the tools being a clear winner.
</p>
<blockquote>
My interest was mostly because I'm working on a book chapter which includes some static analysis content, and there are a couple of these tools that I include in my own builds, but I don't do much with the output of them. However I didn't want to drop anything from the chapter if it was actually a valuable tool and I was just missing the point - pretty much all the tools got a good number of votes though, so I'll be covering all of the [options].
</blockquote>
<p>
According to <a href="http://www.flickr.com/photos/lornajane/5993620876/">her results</a>, the most used tool by developers is the <a href="http://pear.php.net/package/php_codesniffer">PHP_CodeSniffer</a> with the <a href="http://phpmd.org/">PHP Mess Detector</a> and <a href="https://github.com/sebastianbergmann/phpcpd">PHP Copy & Paste Detector</a> tied for second place.
</p>]]></description>
      <pubDate>Wed, 03 Aug 2011 10:50:22 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Eric Hogue's Blog: Late Static Binding]]></title>
      <guid>http://www.phpdeveloper.org/news/16235</guid>
      <link>http://www.phpdeveloper.org/news/16235</link>
      <description><![CDATA[<p>
<i>Eric Hogue</i> has a <a href="http://erichogue.ca/2011/04/14/late-static-binding/">recent post to his blog</a> looking at one of the more tricky aspects of the latest versions of PHP (the 5.3.x series) - late static binding. In a nutshell, late static binding (LSB) lets static classes and methods work more correctly than before. <i>Eric</i> gets into a bit more detail than that:
</p>
<blockquote>
It came out almost 2 years ago, but it to me that many programmers around me have no idea about it. Myself, I have learned about it around 6 months ago. The PHP documentation defines late static binding as a way to "reference the called class in a context of static inheritance." This definition didn't really help me the first time I read it. Fortunately, there are more explanations in the documentation, and there are good examples. If you haven't, you should read it.
</blockquote>
<p>
To clarify, he includes a code snippet showing the use of the "static" keyword to correctly reference a static method. He also includes in interesting bit about when's a good time to use it.
</p>]]></description>
      <pubDate>Fri, 22 Apr 2011 09:14:34 -0500</pubDate>
    </item>
  </channel>
</rss>
