<?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:35:52 -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[Bence Eros' Blog: Getters, setters, performance]]></title>
      <guid>http://www.phpdeveloper.org/news/16580</guid>
      <link>http://www.phpdeveloper.org/news/16580</link>
      <description><![CDATA[<p>
<i>Bence Eros</i> has put together <a href="http://erosbence.blogspot.com/2011/07/getters-setters-performance.html">a new post to his blog</a> looking at some of the results he's found from performance testing the use of getters and setters in PHP.
</p>
<blockquote>
The usage of getter and setter methods instead of public attributes became very popular in the PHP community, and it's going to become the standard coding convention of so many PHP libraries and frameworks. On the other hand many developers - including me too - strongly unrecommend such convention, because of its performance overhead. I wanted to make some performance comparison for years, and today I had time to do that. In this post I would like to show what I found.
</blockquote>
<p>
He starts with a question every developer asks as their working in their application - why and when should they use getters and setters for their classes. He talks about using them as primary functionality or as fallbacks only when needed. He includes the simple benchmarking script he used to compare accessing/setting public attributes directly and using a getter/setter to do the same. The results aren't very surprising if you think about the "magic" that has to happen for getters and setters to work. See <a href="http://erosbence.blogspot.com/2011/07/getters-setters-performance.html">the rest of the post</a> for those numbers.
</p>]]></description>
      <pubDate>Tue, 12 Jul 2011 11:39:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Web Developer Juice: PHP Magic Functions: Best Part of Object Oriented PHP - Part 2]]></title>
      <guid>http://www.phpdeveloper.org/news/16361</guid>
      <link>http://www.phpdeveloper.org/news/16361</link>
      <description><![CDATA[<p>
Web Developer Juice has posted <a href="http://www.webdeveloperjuice.com/2011/05/09/php-magic-functions-best-part-of-object-oriented-php-%E2%80%93-part-2/">the second part of their series</a> looking at some of the "magic functions" that PHP has to offer - special functions that do automagic things in your scripts and classes. Part one can be <a href="http://phpdeveloper.org/news/16288">found here</a>.
</p>
<blockquote>
In my <a href="http://www.webdeveloperjuice.com/2011/04/28/php-magic-functions-best-part-of-object-oriente-php/">previous post</a> ( PHP Magic Functions ), I discussed about __construct, __destruct, __call and __callStatic. Lets explore a few more magic functions...
</blockquote>
<p>In this latest part of the series they look at three functions:</p>
<ul>
<li>__set/__get
<li>__invoke
</ul>]]></description>
      <pubDate>Thu, 19 May 2011 10:14:27 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Web Developer Juice: PHP Magic Functions: Best Part of Object Oriented PHP - Part 1]]></title>
      <guid>http://www.phpdeveloper.org/news/16288</guid>
      <link>http://www.phpdeveloper.org/news/16288</link>
      <description><![CDATA[<p>
On the Web Developer Juice blog there's a <a href="http://www.webdeveloperjuice.com/2011/04/28/php-magic-functions-best-part-of-object-oriente-php/">recent post</a>, the first part in a series</a> looking at one of the more handy features of the recent releases of PHP - the magic functions (some which were added in the PHP 5.x series).
</p>
<blockquote>
There are some reserved function names  in PHP class starting with __ ( double underscore ). These are <a href="http://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor">__construct</a>, <a href="http://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor">__destruct</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members">__isset</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members">__unset</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods">__call</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods">__callStatic</a>, <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep">__sleep</a>, <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep">__wakeup</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members">__get</a>, <a href="http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.members">__set</a>, <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring">__toString</a>, <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.set-state">__set_state</a>, <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.invoke">__invoke</a> and <a href="http://www.php.net/manual/en/language.oop5.cloning.php">__clone</a>. You cannot use these functions to serve your logical purpose but these are meant to be used for providing magic functionality.
</blockquote>
<p>
They go through some of the above methods and talk about what role they can play in your code and, for some, a brief bit of code to explain how it works. This first part covers __construct/__destruct and __call/__callStatic.
</p>]]></description>
      <pubDate>Tue, 03 May 2011 11:57:08 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Matthew Weier O'Phinney's Blog: Dependency Injection: An analogy]]></title>
      <guid>http://www.phpdeveloper.org/news/16081</guid>
      <link>http://www.phpdeveloper.org/news/16081</link>
      <description><![CDATA[<p>
For those still grappling with the concept of dependency injection, <i>Matthew Weier O'Phinney</i> has <a href="http://weierophinney.net/matthew/archives/260-Dependency-Injection-An-analogy.html">posted an analogy</a> that could help make the concept a bit more clear.
</p>
<blockquote>
I've been working on a proposal for including service locators and dependency injection containers in Zend Framework 2.0, and one issue I've had is trying to explain the basic concept to developers unfamiliar with the concepts -- or with pre-conceptions that diverge from the use cases I'm proposing.
</blockquote>
<p>
Using his wife as a sample sounding board, he came up with a restaurant-based analogy to help explain the concept - asking for certain pre-planned things but wanting customizations. He reminds developers that there's not much "magic" to DI. Things are all well defined from the outset and you only have to use it when you want.
</p>]]></description>
      <pubDate>Tue, 22 Mar 2011 12:36:20 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Jose da Silva's Blog: Revisiting PHP 5.3 __invoke magic method]]></title>
      <guid>http://www.phpdeveloper.org/news/15392</guid>
      <link>http://www.phpdeveloper.org/news/15392</link>
      <description><![CDATA[<p>
In a new post to his blog <i>Jose da Silva</i> <a href="http://blog.josedasilva.net/revisiting-php-5-3-__invoke-magic-method/">briefly looks at</a> a feature that was introduced in the PHP 5.3.x series of the language - the __invoke magic method.
</p>
<blockquote>
PHP version 5.3 introduced a new magic method designed __invoke, this method is called when a script tries to call an object as a function. [...] As php cannot accommodate pseudo-first-class functions, the __invoke method can be used to suppress this language limitation. On other hand you can use this for simpler things as pass a function around. 
</blockquote>
<p>
He includes a simple code example that shows a basic class being called via a variable name - $c('ford') - and the result of its __invoke method being called. He notes that <a href="http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.invoke">the method</a>, in his opinion, could make for less clean code.
</p>]]></description>
      <pubDate>Fri, 05 Nov 2010 12:42:04 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[NETTUTS.com: Deciphering Magic Methods in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/14821</guid>
      <link>http://www.phpdeveloper.org/news/14821</link>
      <description><![CDATA[<p>
Whether you're new to the language or to the more advanced features of it, you might find the magic methods a bit confusing at first. Thankfully, NETTUTS.com is here to help with <a href="http://net.tutsplus.com/tutorials/php/deciphering-magic-methods-in-php/">this new tutorial</a> on what they are and how to use them in your code.
</p>
<blockquote>
PHP provides a number of 'magic' methods that allow you to do some pretty neat tricks in object oriented programming. These methods, identified by a two underscore prefix (__), function as interceptors that are automatically called when certain conditions are met. Magic methods provide some extremely useful functionality, and this tutorial will demonstrate each method's use.
</blockquote>
<p>
They define a sample class so you can see them in context - a Device and a Battery. They cover constructors/destructors, get/set, isset/unset, toString, clone and more (including the callStatic that's only in the recent PHP 5.3 versions of the language).
</p>]]></description>
      <pubDate>Tue, 20 Jul 2010 13:27:44 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Think Vitamin: 9 Magic Methods for PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/14614</guid>
      <link>http://www.phpdeveloper.org/news/14614</link>
      <description><![CDATA[<p>
For those just getting started with PHP and wondering what these "magic methods" are all about (and they can be a little confusing for someone not used to the language), <i>Lorna Mitchell</i> has <a href="http://carsonified.com/blog/dev/9-magic-methods-for-php/">a new tutorial</a> posted to the Think Vitamin blog on just that topic.
</p>
<blockquote>
The "magic" methods are ones with special names, starting with two underscores, which denote methods which will be triggered in response to particular PHP events. That might sound slightly automagical but actually it's pretty straightforward, we already saw an example of this in the <a href="http://carsonified.com/blog/dev/getting-started-with-oop-php5-part-2/">last post</a>, where we used a constructor - so we'll use this as our first example.
</blockquote>
<p>She talks about nine of these magic functions including:</p>
<ul>
<li>__get/__set for variable handling
<li>__sleep/__wakeup for serializing data
<li>__call/__callStatic for methods in a class
<li>__construct/__destruct for making and destroying classes
</ul>]]></description>
      <pubDate>Mon, 07 Jun 2010 13:58:41 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: The Destruct Magic Function in PHP 5]]></title>
      <guid>http://www.phpdeveloper.org/news/12742</guid>
      <link>http://www.phpdeveloper.org/news/12742</link>
      <description><![CDATA[<p>
DevShed has posted the <a href="http://www.devshed.com/c/a/PHP/The-Destruct-Magic-Function-in-PHP-5/">second to last part</a> of their tutorial series looking at the magic functions in PHP. This time they focus on the destruct function, a method that is fired off when an object is being removed from memory.
</p>
<blockquote>
There are a few [other methods] that can be really useful for performing relatively complex tasks with a minimal amount of code. That's exactly the case with the "__destruct()" method, which will be called automatically by the PHP engine before destroying an instance of a particular class at the end of a script. 
</blockquote>
<p>
They update their <a href="http://www.devshed.com/c/a/PHP/The-Destruct-Magic-Function-in-PHP-5/2/">example class</a> with a new __destruct method that takes the user information inserted previously, serializes it and drops it into the current session.
</p>]]></description>
      <pubDate>Wed, 24 Jun 2009 08:46:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: The Autoload Magic Function in PHP 5]]></title>
      <guid>http://www.phpdeveloper.org/news/12734</guid>
      <link>http://www.phpdeveloper.org/news/12734</link>
      <description><![CDATA[<p>
DevShed has posted <a href="http://www.devshed.com/c/a/PHP/The-Autoload-Magic-Function-in-PHP-5/">the latest article</a> (the last) in their series looking at the "magic functions" that PHP has to offer. This time they take a closer look at the autoload functionality.
</p>
<blockquote>
PHP 5 offers yet another magic method that can be extremely useful for loading classes automatically, without having to use explicitly any "include()/include_once()" or "require()/require_once()" function. As the article's title suggests, I'm talking specifically about the "__autoload()" function, which deserves a deeper analysis.
</blockquote>
<p>
<a href="http://www.devshed.com/c/a/PHP/The-Autoload-Magic-Function-in-PHP-5/3/">Their example</a> shows how to define the __authoload method for your application to load in libraries as they're needed, without having to specifically define them.
</p>]]></description>
      <pubDate>Tue, 23 Jun 2009 07:56:57 -0500</pubDate>
    </item>
  </channel>
</rss>

