<?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>Sun, 12 Feb 2012 21:56:56 -0600</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Refulz.com: The __toString() Method - Objects as Strings]]></title>
      <guid>http://www.phpdeveloper.org/news/17523</guid>
      <link>http://www.phpdeveloper.org/news/17523</link>
      <description><![CDATA[<p>
On the Refulz.com blog there's a <a href="http://php.refulz.com/magic-methods-in-php-tostring-method/">recent post</a> introducing the __toString() magic method in PHP. This handy method allows you to define how to return an object when it's referenced as a string.
</p>
<blockquote>
We started the study of PHP magic methods by learning about <a href="http://php.refulz.com/magic-methods-in-php-__get-method/">__get() magic method</a>. [...] PHP is loosely typed language and same variable can be used or referred as string, number or object. The __toString() method is called when the code attempts to treat an object like a string. This function does not accept any arguments and should return a string.
</blockquote>
<p>
Some quick code is included showing how it works - returning a combined string made from two private class properties when the object ($obj) is echoed out. They also show multiple ways of using the method in both pre- and post-PHP 5.2.
</p>]]></description>
      <pubDate>Thu, 09 Feb 2012 09:27:19 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Sharon Levy's Blog: PHP Version]]></title>
      <guid>http://www.phpdeveloper.org/news/17353</guid>
      <link>http://www.phpdeveloper.org/news/17353</link>
      <description><![CDATA[<p>
<i>Sharon Levy</i> has a new post to her blog showing a trick she's come up with to show the PHP version information (usually found in the <a href="http://php.net/phpinfo">phpinfo</a>) <a href="http://slevy1.wordpress.com/2011/12/12/php-version/#more-2225">even when it's disabled</a>.
</p>
<blockquote>
Sometimes the most crucial, basic piece of information can seem so hard to find. For example, suppose you wanted to find out what version of PHP your remote webhost provides to shared hosting users? What would you do? [...] For development purposes it can be helpful having phpinfo() available, but on a live shared host, you may discover as I did recently that it is no longer available; your host may have disabled it.
</blockquote>
<p>
She includes three other ways you can use to get the version of PHP you're working with:
</p>
<ul>
<li>If you have command line access, running "php -v"
<li>Using the <a href="http://php.net/phpversion">phpversion</a> function (or PHP_VERSION constant)
<li>Appending a certain value to the URL (only works in some cases)
</ul>]]></description>
      <pubDate>Thu, 05 Jan 2012 13:20:40 -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[PHPMaster.com: Understanding the Factory Method Design Pattern]]></title>
      <guid>http://www.phpdeveloper.org/news/17272</guid>
      <link>http://www.phpdeveloper.org/news/17272</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new design pattern-focused that introduces you to using the <a href="http://phpmaster.com/understanding-the-factory-method-design-pattern/">Factory method</a> to create new objects on the fly.
</p>
<blockquote>
The Factory Method pattern is a design pattern used to define a runtime interface for creating an object. It's called a factory because it creates various types of objects without necessarily knowing what kind of object it creates or how to create it.
</blockquote>
<p>
Code is included showing how to make creating "Product_*" classes as simple as calling a "build()" method with the type. A slightly more complex situation is also included - building factories inside of factory methods. For more about the Factory design pattern, check out <a href="http://en.wikipedia.org/wiki/Factory_method_pattern">its Wikipedia page</a> (that includes some common uses and some pitfalls to watch out for).
</p>]]></description>
      <pubDate>Fri, 16 Dec 2011 12:15:54 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Michael Nitschinger's Blog: Quick Tip: Lithium Redirect]]></title>
      <guid>http://www.phpdeveloper.org/news/16868</guid>
      <link>http://www.phpdeveloper.org/news/16868</link>
      <description><![CDATA[<p>
<i>Michael Nitschinger</i> has a "quick tip" posted in <A href="http://nitschinger.at/Quick-Tip-Lithium-Redirect">this new entry</a> to his blog - how to handle a redirect in a <a href="http://lithify.me">Lithium</a>-framework based application.
</p>
<blockquote>
While migrating pastium over to MongoDB (from CouchDB), I found [a] snippet in the routes.php file [that makes it so] when the user enters the application via the root url (/), he instantly gets redirected to /pastes/add (or a different URL if you have custom routes configured). This may seem ok at first, but there's a problem. It doesn't take URLs into account that don't live directly under the document root. 
</blockquote>
<p>
The snippet he references and others showing how to correct the issue are included - replacing the location array controller/action information with the static class information for the route in a match() call. For more information on the routing in Lithium, see <a href="http://lithify.me/docs/lithium/net/http/Route">these</a> <a href="http://lithify.me/docs/lithium/net/http/Router">manual</a> pages.
</p>]]></description>
      <pubDate>Fri, 16 Sep 2011 10:02:21 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Liip Blog: First Release of Proxy-Object]]></title>
      <guid>http://www.phpdeveloper.org/news/16597</guid>
      <link>http://www.phpdeveloper.org/news/16597</link>
      <description><![CDATA[<p>
On the Liip blog <i>Bastian Feder</i> has announced the first release of a tool that helps you proxy your objects (overlay them with a layer that exposes properties and methods) following the <a href="http://en.wikipedia.org/wiki/Proxy_pattern">proxy object design pattern</a> in PHP.
</p>
<blockquote>
The outcome is this little library making it much easier to generate a proxy of your system under test (SUT). Another thought on this library was, that it should be very easy to use if you know the way to mock classes and methods in PHPUnit. Proxy-object has almost the same API, but does not change the behavior of the proxied class/method. The only purpose is to expose hidden methods and members.
</blockquote>
<p>
The scripts, <a href="http://github.com/lapistano/proxy-object">found on github</a>, give you a simple way to define a proxy over a given class' functionality and define methods/member variables to be exposed. He includes two code examples, one of each type. There's also an example of making the proxy object without calling the constructor, useful in certain cases when the initialization of the object doesn't need to happen.
</p>
<p>
You can also find out more about the usage of this tool in <a href="http://blog.bastian-feder.de/blog/029_proxyObject.html">this new post</a> to <i>Bastian</i>'s blog.
</p>]]></description>
      <pubDate>Fri, 15 Jul 2011 11:06:34 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog: PHP typehinting gotcha in exceptions/methods]]></title>
      <guid>http://www.phpdeveloper.org/news/16591</guid>
      <link>http://www.phpdeveloper.org/news/16591</link>
      <description><![CDATA[<p>
<i>Jani Hartikainen</i> has a new post with a gotcha he came across when <a href="http://codeutopia.net/blog/2011/07/13/php-typehinting-gotcha-in-exceptionsmethods/">using typehinting in exceptions and methods</a>.
</p>
<blockquote>
A small gotcha I recently ran into: If you use typehinting, PHP never checks that the class your typehint specifies actually exists!
</blockquote>
<p>
He includes simple examples that define the class type hint as some random string and PHP never throws an error for it. He also notes that it's even worse when dealing with namespaces - how it handles exceptions locally unless you specify otherwise. Of course, these "features" can be put to good use in the right situations, but they can be confusing for a developer without a keen eye.
</p>]]></description>
      <pubDate>Thu, 14 Jul 2011 10:41:55 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Matthew Weier O'Phinney's Blog: Proxies in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16555</guid>
      <link>http://www.phpdeveloper.org/news/16555</link>
      <description><![CDATA[<p>
In a new blog post <i>Matthew Weier O'Phinney</i> has <a href="http://weierophinney.net/matthew/archives/263-Proxies-in-PHP.html">taken a look at proxy objects</a> (the Proxy design pattern) and how it differs from some of the other popular patterns.
</p>
<blockquote>
Of the other patterns mentioned, the one closest to the Proxy is the Decorator. In the case of a Decorator, the focus is on adding functionality to an existing object -- for instance, adding methods, processing input before delegating to the target object, or filtering the return of a method from a target object.
</blockquote>
<p>
Proxies stand in for objects and have several benefits for your application that may or may not need all of the overhead a full object could cause. <i>Matthew</i> focuses on one benefit in particular - consuming and controlling access to another object. He sets up a problem of wanting to use properties/methods on objects that aren't exposed directly (like a protected method). His solution is a proxy layer class on top of the original object. He includes a few "gotchas" to look out for when using this technique including overwriting all necessary methods and copying over all of the needed properties.
</p>]]></description>
      <pubDate>Wed, 06 Jul 2011 08:10:08 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Till Klampaeckel's Blog: RFC: Mocking protected methods]]></title>
      <guid>http://www.phpdeveloper.org/news/16481</guid>
      <link>http://www.phpdeveloper.org/news/16481</link>
      <description><![CDATA[<p>
<i>Till Klampaeckel</i> has <a href="http://till.klampaeckel.de/blog/archives/158-RFC-Mocking-protected-methods.html">a new post</a> to his blog today looking at the method he's found (through some help from others) to be able to mock out protected methods in his unit tests.
</p>
<blockquote>
I wrote a couple tests for a small CouchDB access wrapper today. But when I wrote the implementation itself, I realized that my class setup depends on an actual CouchDB server being available and here my journey began.
</blockquote>
<p>
It was his first experience trying to mock out parts of a class, and he found it a bit difficult to use even after reading <a href="http://sebastian-bergmann.de/archives/881-Testing-Your-Privates.html">this article</a> from <i>Sebastian Bergmann</i>. He ended up, as a first solution, making a "fake" (a term from Ruby testing) that just returned the basic JSON string of an error. Thanks to comments on the post, though, he was able to come up with a more correct solution using getMock() to create a stub and apply an expects() to his "makeRequest" method.
</p>]]></description>
      <pubDate>Thu, 16 Jun 2011 13:48:33 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Slawek Lukasiewicz's Blog: Zend Framework: Reflection]]></title>
      <guid>http://www.phpdeveloper.org/news/16403</guid>
      <link>http://www.phpdeveloper.org/news/16403</link>
      <description><![CDATA[<p>
<i>Slawek Lukasiewicz</i> has a recent post to his blog looking at a tool that comes bundled with PHP that can help you find out more about your own code (or really any other piece of code out there) - <a href="http://www.leftjoin.net/2011/05/zend-framework-reflection/">the Reflection API</a>. In his post he looks specifically at the functionality the <a href="http://framework.zend.com">Zend Framework</a> has built on top of the base <a href="http://php.net/reflection">PHP API</a>.
</p>
<blockquote>
Zend Framework has own Reflection extension. It is mostly build upon genuine <a href="http://php.net/manual/en/book.reflection.php">PHP Reflection API</a> and extends existing features. The completely new Zend_Reflection module feature is introspection of docBlock tags.
</blockquote>
<p>
He includes two code examples using this component of the framework - grabbing the docblock off of a specific method (and even how to grab specific tags from inside it) and how to grab the body content out of a given method, with or without the docblock attached.
</p>]]></description>
      <pubDate>Tue, 31 May 2011 08:18:56 -0500</pubDate>
    </item>
  </channel>
</rss>

