<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Trait-like Functionality for PHP</title>
	<atom:link href="http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/</link>
	<description>Barking on about PHP, MySQL and Zend Framework</description>
	<lastBuildDate>Wed, 11 Jan 2012 16:01:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Ashley Kitson</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-782</link>
		<dc:creator>Ashley Kitson</dc:creator>
		<pubDate>Wed, 13 Apr 2011 06:31:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-782</guid>
		<description>Steve,  Nice bit of work which I&#039;ve used to get some stuff out of an ORM class and into traits and behaviour patterns which is much better.  One comment that might help others;  Your implementation assumes that all trait methods being used will accept the calling object instance as a first parameter.  This is redundant (imho) and is better handled by the constructor to the trait.  So rather than having;

$args = array_merge( array( $object ), $args );

in the callmethod()

if the trait methods require access to the calling object, it is better to pass it in during construction e.g.;

	/**
	 * Add extended details trait
	 * Provides:
	 * 		$this-&gt;getExtended()
	 * 		$this-&gt;addExtended(array $details)
	 * 		$this-&gt;updateExtended(array $details)
	 */
	function _initTraits() {
		parent::_initTraits();
		$this-&gt;_registerTrait( new Trait_ZWIdentExtended(array(&#039;model&#039;=&gt;$this)));
	}

This removes an element of dependency if it isn&#039;t required.

Cheers</description>
		<content:encoded><![CDATA[<p>Steve,  Nice bit of work which I&#8217;ve used to get some stuff out of an ORM class and into traits and behaviour patterns which is much better.  One comment that might help others;  Your implementation assumes that all trait methods being used will accept the calling object instance as a first parameter.  This is redundant (imho) and is better handled by the constructor to the trait.  So rather than having;</p>
<p>$args = array_merge( array( $object ), $args );</p>
<p>in the callmethod()</p>
<p>if the trait methods require access to the calling object, it is better to pass it in during construction e.g.;</p>
<p>	/**<br />
	 * Add extended details trait<br />
	 * Provides:<br />
	 * 		$this-&gt;getExtended()<br />
	 * 		$this-&gt;addExtended(array $details)<br />
	 * 		$this-&gt;updateExtended(array $details)<br />
	 */<br />
	function _initTraits() {<br />
		parent::_initTraits();<br />
		$this-&gt;_registerTrait( new Trait_ZWIdentExtended(array(&#8216;model&#8217;=&gt;$this)));<br />
	}</p>
<p>This removes an element of dependency if it isn&#8217;t required.</p>
<p>Cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-773</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 18 May 2010 10:28:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-773</guid>
		<description>Hey Harald, thanks for the comment.

&gt;&gt; A ‘Trait’ is what we call a Mixin.
Who/what is we? :) 

As I understand it, Mixins are more complex than traits and carry some of the same problems as mulitple inheritance. At least as far as PHP goes, the terminology is all a bit vague until something actually gets implemented.

&gt;&gt; But I dislike the usage of __call for the trait-methods because a Reflection cant list them. This prevent “code completion” and “class browsers”)
Agreed - this approach does have some drawbacks. That said, so do the alternatives. 

If you use a code generation technique as suggested by Ralf, you&#039;re still duplicating code and need to re-run the code generation whenever one of the traits/plugins/mixins is modified. The only way we&#039;re likely to see a completely &quot;clean&quot; implementation is if/when some form of horizontal code re-use becomes a feature of PHP.

&gt;&gt; I also would say it is not necessary to make the access to $_traitBroker private. Because you provide access to the whole Object via getTraitBroker.
A tiny implementation detail, but yes, you&#039;re right.

&gt;&gt; So you can make a cleaner Interface with lesser code and no ‘magic’
How? Perhaps I&#039;m missing something, but I don&#039;t see what your suggestion is?</description>
		<content:encoded><![CDATA[<p>Hey Harald, thanks for the comment.</p>
<p>>> A ‘Trait’ is what we call a Mixin.<br />
Who/what is we? <img src='http://www.stevehollis.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p>As I understand it, Mixins are more complex than traits and carry some of the same problems as mulitple inheritance. At least as far as PHP goes, the terminology is all a bit vague until something actually gets implemented.</p>
<p>>> But I dislike the usage of __call for the trait-methods because a Reflection cant list them. This prevent “code completion” and “class browsers”)<br />
Agreed &#8211; this approach does have some drawbacks. That said, so do the alternatives. </p>
<p>If you use a code generation technique as suggested by Ralf, you&#8217;re still duplicating code and need to re-run the code generation whenever one of the traits/plugins/mixins is modified. The only way we&#8217;re likely to see a completely &#8220;clean&#8221; implementation is if/when some form of horizontal code re-use becomes a feature of PHP.</p>
<p>>> I also would say it is not necessary to make the access to $_traitBroker private. Because you provide access to the whole Object via getTraitBroker.<br />
A tiny implementation detail, but yes, you&#8217;re right.</p>
<p>>> So you can make a cleaner Interface with lesser code and no ‘magic’<br />
How? Perhaps I&#8217;m missing something, but I don&#8217;t see what your suggestion is?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Harald Stowasser</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-772</link>
		<dc:creator>Harald Stowasser</dc:creator>
		<pubDate>Tue, 18 May 2010 09:50:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-772</guid>
		<description>A &#039;Trait&#039; is what we call a Mixin.

But I dislike the usage of __call for the trait-methods because a Reflection cant list them. This prevent “code completion” and “class browsers”)

I also would say it is not necessary to make the access to $_traitBroker private. Because you provide access to the whole Object via getTraitBroker.

So you can make a cleaner Interface with lesser code and no &#039;magic&#039;</description>
		<content:encoded><![CDATA[<p>A &#8216;Trait&#8217; is what we call a Mixin.</p>
<p>But I dislike the usage of __call for the trait-methods because a Reflection cant list them. This prevent “code completion” and “class browsers”)</p>
<p>I also would say it is not necessary to make the access to $_traitBroker private. Because you provide access to the whole Object via getTraitBroker.</p>
<p>So you can make a cleaner Interface with lesser code and no &#8216;magic&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-699</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 14 Apr 2010 16:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-699</guid>
		<description>Thanks Ralf!

I like your reflection/code generation approach and the &quot;compatibility&quot; with code assist is a big plus. Sadly, one downside of complex OO approaches is that most IDEs just can&#039;t handle them!

I haven&#039;t played around with Zend_CodeGenerator yet but it looks like an interesting component.

Thanks again for the comment.</description>
		<content:encoded><![CDATA[<p>Thanks Ralf!</p>
<p>I like your reflection/code generation approach and the &#8220;compatibility&#8221; with code assist is a big plus. Sadly, one downside of complex OO approaches is that most IDEs just can&#8217;t handle them!</p>
<p>I haven&#8217;t played around with Zend_CodeGenerator yet but it looks like an interesting component.</p>
<p>Thanks again for the comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ralf</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-697</link>
		<dc:creator>Ralf</dc:creator>
		<pubDate>Mon, 12 Apr 2010 15:51:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-697</guid>
		<description>Hi Steve!

Interesting indeed. It seems like a generic object plug-in system. Sure, this fits OOPLs other then PHP as well.

I recently sketched out a solution witch uses code generation for mixing-in other classes functionality. While this approach does not make massive use of PHP&#039;s magic method mechanics, it enables the developer to have code assist from an IDE. But this is only kind of a side effect. The post is really about generating type-checking property accessors.

Have a look: http://blog.uebercode.org/2010/03/static-annotation-driven-php-code.html

I would appreciate some comments on this ;)

Regards!</description>
		<content:encoded><![CDATA[<p>Hi Steve!</p>
<p>Interesting indeed. It seems like a generic object plug-in system. Sure, this fits OOPLs other then PHP as well.</p>
<p>I recently sketched out a solution witch uses code generation for mixing-in other classes functionality. While this approach does not make massive use of PHP&#8217;s magic method mechanics, it enables the developer to have code assist from an IDE. But this is only kind of a side effect. The post is really about generating type-checking property accessors.</p>
<p>Have a look: <a href="http://blog.uebercode.org/2010/03/static-annotation-driven-php-code.html" rel="nofollow">http://blog.uebercode.org/2010/03/static-annotation-driven-php-code.html</a></p>
<p>I would appreciate some comments on this <img src='http://www.stevehollis.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron McGowan</title>
		<link>http://www.stevehollis.com/2010/04/trait-like-functionality-for-php/comment-page-1/#comment-287</link>
		<dc:creator>Aaron McGowan</dc:creator>
		<pubDate>Tue, 06 Apr 2010 08:23:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevehollis.com/?p=134#comment-287</guid>
		<description>Very cool and an interesting thought Steve.

Aaron</description>
		<content:encoded><![CDATA[<p>Very cool and an interesting thought Steve.</p>
<p>Aaron</p>
]]></content:encoded>
	</item>
</channel>
</rss>

