<?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>Sat, 25 May 2013 07:36:05 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Extending Twig Templates: Inheritance, Filters, and Functions]]></title>
      <guid>http://www.phpdeveloper.org/news/19467</guid>
      <link>http://www.phpdeveloper.org/news/19467</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial for the <a href="http://twig.sensiolabs.org/">Twig</a> templating users out there showing you how to <a href="http://phpmaster.com/extending-twig-templates-inheritance-filters-and-functions/">extend your templates</a> via inheritance, filters and functions - all abilities already built in to the tool.
</p>
<blockquote>
When working within an MVC architecture, it's common to use a template library to populate the dynamic content of our views. There are dozens of such libraries available for PHP, but Twig is one of the standouts because of the ability to extend core features with custom implementations. In this article we'll explore how Twig templates can be extended using template inheritance, filters, and functions.
</blockquote>
<p>
He starts first with some of the common limitations of templating frameworks (extension) and how Twig gets around this. He shows the use of the "extends" keyword and the "block"/"endblock" for splitting up the page into reusable chunks. He also shows how to use filters and functions in your Twig tags, allowing for more customized content and functionality for your output.
</p>
Link: http://phpmaster.com/extending-twig-templates-inheritance-filters-and-functions/]]></description>
      <pubDate>Tue, 16 Apr 2013 11:05:22 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso: Multiple inheritance with PHP and Traits]]></title>
      <guid>http://www.phpdeveloper.org/news/18919</guid>
      <link>http://www.phpdeveloper.org/news/18919</link>
      <description><![CDATA[<p>
<i>Gonzalo Ayuso</i> has a new post today showing how you can use <a href="http://php.net/traits">traits</a> in PHP to simulate <a href="http://gonzalo123.com/2012/12/17/multiple-inheritance-with-php-and-traits/">a kind of multiple inheritance</a>.
</p>
<blockquote>
Multiple inheritance isn't allowed in PHP. [It's not] possible with PHP (in Java is not possible either), but today we can do something similar (is not the exactly the same) with Traits. Let me explain that: Instead of classes we can create Traits.
</blockquote>
<p>
He includes a code example showing the creation of two traits, "Base1" and "Base2", that are implemented (via "use") and the calls to methods on each. He also points out the error condition and message that can come up when there's a conflict in the method names between two or more traits. This is relatively easy to solve with the mapping ability of the "use" statement (code example included for that too).
</p>]]></description>
      <pubDate>Wed, 19 Dec 2012 13:17:48 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Reusing Implementation - a Walk-through of Inheritance, Composition, and Delegation]]></title>
      <guid>http://www.phpdeveloper.org/news/18229</guid>
      <link>http://www.phpdeveloper.org/news/18229</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial posted that wants to <a href="http://phpmaster.com/reusing-implementation-a-walk-through-of-inheritance-composition-and-delegation/">provide a guide</a> to walk you through a trio of ideas to help with code/idea reuse in your applications - inheritance, composition and delegation.
</p>
<blockquote>
The popular belief is that reusing implementation, thus producing DRYer code, boils down to exploiting the benefits that Inheritance provides, right? Well, I wish it was that easy! [...] If you don't know what path to travel when it comes to reusing implementation, in this article I'll be doing a humble walk-through on the Inheritance/Composition/Delegation trio in an attempt to showcase, side by side, some of their most appealing virtues and clunky drawbacks.
</blockquote>
<p>
He starts off with a look at Inheritance, showing with a small code sample showing the creation of an interface and a resulting PDO adapter class implementing it. He also shows the concept of composition, following the ideas of the <a href="http://en.wikipedia.org/wiki/Adapter_pattern">Adapter pattern</a>. In his Delegation example he shows how to implement the creation of the connection object as a part of the class' creation.
</p>]]></description>
      <pubDate>Mon, 16 Jul 2012 11:42:54 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Layer Supertype Pattern: Encapsulating Common Implementation in Multi-Tiered Systems]]></title>
      <guid>http://www.phpdeveloper.org/news/18176</guid>
      <link>http://www.phpdeveloper.org/news/18176</link>
      <description><![CDATA[<p>
On PHPMaster.com there's a new post looking at a design pattern that's commonly in use by developers but they might not know its name - the <a href="http://phpmaster.com/the-layer-supertype-pattern-encapsulating-common-implementation-in-multi-tiered-systems/">Layer Supertype</a> pattern and its use in multi-tiered systems.
</p>
<blockquote>
Inheritance offers a straightforward way to easily spawn a large number of objects that are semantically related to each other without having duplicate code. The concept is ridiculously simple - yet powerful: you first drop as much logic as possible within the boundaries of a base type (usually an abstract class, but it could be a concrete one), and then start deriving refined subtypes according to more specific requirements. [...] Not surprisingly, this repetitive encapsulation/derivation cycle lays down on the formalities of a design pattern known as <a href="http://martinfowler.com/eaaCatalog/layerSupertype.html">Layer Supertype</a>.
</blockquote>
<p>
They describe the "supertype" as a replacement for an overly bloated domain-related model. Their example replaces a PostInterface/CommentInterface with a more generic "AbstractEntity" that handles some of the basics for you - getting/setting, checking a field, setting an ID and outputing the information to an array.
</p>]]></description>
      <pubDate>Wed, 04 Jul 2012 17:13:39 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Refulz.com: Traits - Method Precedence and Conflict resolution]]></title>
      <guid>http://www.phpdeveloper.org/news/18029</guid>
      <link>http://www.phpdeveloper.org/news/18029</link>
      <description><![CDATA[<p>
On the Refulz.com site today they've posted a new tutorial looking at the use of traits and <a href="http://php.refulz.com/traits-method-precedence-and-conflict-resolution/">how to resolve conflicts</a> and work with method precedence.
</p>
<blockquote>
In our previous post about the <a href="http://php.refulz.com/traits-in-php-multiple-and-nested-traits/">multiple and nested traits</a>, we read how nested and multiple traits can be used in a class. In such cases, there is a possibility of the same method name existing in the trait, and the class using the trait. Furthermore, the same method name might also be present in the parent class of the class using traits. It is important to understand how the precedence order works for such cases.
</blockquote>
<p>
First they look at the precedence between classes and traits with the class always winning...unless the method is inherited from a parent class. They also mention the order when it comes to using the "insteadof" and "as" operators as a way to get around conflicts between traits.
</p>]]></description>
      <pubDate>Thu, 31 May 2012 10:07:25 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Liip Blog: Table Inheritance with Doctrine]]></title>
      <guid>http://www.phpdeveloper.org/news/17742</guid>
      <link>http://www.phpdeveloper.org/news/17742</link>
      <description><![CDATA[<p>
On the Liip blog there's a recent post looking at <a href="http://blog.liip.ch/archive/2012/03/27/table-inheritance-with-doctrine.html">table inheritance with Doctrine</a>, the popular <a href="http://www.doctrine-project.org/">PHP ORM tool</a>. In the post, <i>Daniel Barsotti</i> talks about a database model that needed some updating due to their searching needs.
</p>
<blockquote>
Our first idea, and it was not that bad, Drupal does just the same, was to have a database table with the common fields, a field containing the type of item (it's either an event or a blog post) and a data field where we serialized the corresponding PHP object. This approach was ok until we had to filter or search LabLog items based on fields that were contained in the serialized data.
</blockquote>
<p>
To resolve the issue they turned to multiple table inheritance, relating the LabLogItem to both a BlogPost and Event. They also show how it could be modeled with a single table, but opt for the multiple method. Included in the post is the Doctrine-based code showing how to create the parent entity for the LabLogItem and the two child entities for the blog post and event. There's also a brief snippet showing how to use them with the EntityManager. 
</p>]]></description>
      <pubDate>Wed, 28 Mar 2012 09:30:09 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Using Traits in PHP 5.4]]></title>
      <guid>http://www.phpdeveloper.org/news/17522</guid>
      <link>http://www.phpdeveloper.org/news/17522</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial about using a feature in the upcoming PHP release (5.4) to make it easier to work with more modular code - <a href="http://phpmaster.com/using-traits-in-php-5-4/">using traits</a>.
</p>
<blockquote>
In this article I will discuss traits, a new feature introduced in PHP 5.4 to overcome [issues where multiple inheritance is needed]. The concept of traits itself is nothing new to programming and is used in other languages like Scala and Perl. They allows us to horizontally reuse code across independent classes in different class hierarchies.
</blockquote>
<p>
Included in the post is example code showing what the use of a trait looks like and a method for creating a Singleton that can spawn instances of two classes. Also included are examples of:
</p>
<ul>
<li>using multiple traits at once, 
<li>traits made up of traits, 
<li>the importance of order, 
<li>aliasing to avoid conflicts, 
<li>reflection 
<li>and a few other features that come along with their use.
</ul>]]></description>
      <pubDate>Thu, 09 Feb 2012 08:40:50 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Elated.com: Object-Oriented PHP: Working with Inheritance]]></title>
      <guid>http://www.phpdeveloper.org/news/16391</guid>
      <link>http://www.phpdeveloper.org/news/16391</link>
      <description><![CDATA[<p>
On Elated.com there's a new <a href="http://www.elated.com/articles/object-oriented-php-working-with-inheritance/">introduction to working with inheritance in PHP</a> for object-oriented applications. They work through some of the basic concepts including parent/child classes, final and abstract classes and interfaces.
</p> 
<blockquote>
In this article we're going to explore the idea of inheritance in object-oriented programming, and how inheritance works in PHP. With inheritance, your objects and classes can become much more powerful and flexible, and you can save a lot of time and effort with your coding.
</blockquote>
<p>
They start with the basics of how inheritance works and then move right into creating child classes from a parent. Their example code makes a basic forum system (just example code, not fully functioning) with administrators, members and forum creation. They use this as a base to show the method overriding and exposure with "final". The finish it off with examples of two things that can promote good application structure - abstract classes an interfaces.
</p>]]></description>
      <pubDate>Fri, 27 May 2011 09:21:20 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Zend Developer Zone: Creating Web Page Templates with PHP and Twig (part 2)]]></title>
      <guid>http://www.phpdeveloper.org/news/16302</guid>
      <link>http://www.phpdeveloper.org/news/16302</link>
      <description><![CDATA[<p>
On the Zend Developer Zone they've posted the <a href="http://devzone.zend.com/article/14158-Creating-Web-Page-Templates-with-PHP-and-Twig-part-2">second part</a> of <i>Vikram Vaswani</i>'s look at using the <a href="http://twig-project.org">Twig</a> templating engine in your PHP applications. In the first part of the series, he introduced the tool and got started with some simple examples. In this second part, he dives in deeper to some of the advanced features.
</p>
<blockquote>
In this second and concluding segment, I'll look at some of Twig's other features, including such goodies as template inheritance, custom filters and caching. If you enjoyed the first part of this article, keep reading to find out more about what goes on under Twig's hood, and how you can add even more power and flexibility to your templates
</blockquote>
<p>
He looks at template inheritance, parent blocks/child templates, data filtering, the tool's "compilation cache" and working with native plugins.
</p>]]></description>
      <pubDate>Thu, 05 May 2011 13:11:25 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Bence Eros' Blog: Using Inheritance]]></title>
      <guid>http://www.phpdeveloper.org/news/15529</guid>
      <link>http://www.phpdeveloper.org/news/15529</link>
      <description><![CDATA[<p>
In <a href="http://erosbence.blogspot.com/2010/11/using-inheritance.html">this new post</a> to his blog, <i>Bence</i> looks at how inheritance is commonly used in PHP applications and how, if not controlled carefully can be something that creates bad habits among PHP developers.
</p>
<blockquote>
In fact I think that using inheritance all the time is a very big mistake and makes your code hard to maintain and more hard to integrate (the latter is a mistake for application codes and a fatal mistake for libraries). The main problem with inheritance is that if you use it for coupling two classes, then a very important property of the subclass is used up: it's superclass. It is taken, reserved, and it can not be used for anything else furthermore. If you want to connect your subclass to an other class using inheritance, you can't.
</blockquote>
<p>
He recommends avoiding the typical uses of typical superclass/subclass inheritance unless what you're doing specifically requires it. Working with interfaces, abstract classes and good composition planning is a much better idea.
</p>]]></description>
      <pubDate>Thu, 02 Dec 2010 12:14:39 -0600</pubDate>
    </item>
  </channel>
</rss>
