<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Traits &#8211; HU Xiaoxu</title>
	<atom:link href="https://blog.ihuxu.com/tag/traits/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.ihuxu.com</link>
	<description>a software engineer&#039;s blog</description>
	<lastBuildDate>Wed, 18 Jun 2025 15:28:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>PHP 的 Traits：到底是祸害还是好得飞起？</title>
		<link>https://blog.ihuxu.com/php-traits-good-or-bad/</link>
					<comments>https://blog.ihuxu.com/php-traits-good-or-bad/#respond</comments>
		
		<dc:creator><![CDATA[HU Xiaoxu]]></dc:creator>
		<pubDate>Wed, 12 Oct 2016 11:31:27 +0000</pubDate>
				<category><![CDATA[Computer Language]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Original]]></category>
		<category><![CDATA[Traits]]></category>
		<guid isPermaLink="false">http://www.ihuxu.com/blog/?p=6479</guid>

					<description><![CDATA[在 2012 年 3 月初，PHP 团队宣布了 5.4 版本的发布。程序员们对这次的发布已期待许久，因为这一次的升级带来了很多特性的加入。其中，最受追捧的是 Traits。为了构建这次发布的版本，Shammer C 特意为此撰写了一篇文档：如何使用 PHP 的 Traits，我强烈的建议您在读这篇文章之前拜读一下，因为这篇文章需要读者能够对 Traits 有一定的基础了解。 Traits 已经被 PHP 社区广泛的接受，最为关键的是因为它包含了其他 Java、C++ 和 Python 编程语言的特性。除此之外，Traits 也被广大的网友们神化了。那些程序员狂砍这种特性将给他们的项目带来多么大的益处，尤其指出它是能够替代面向对象（OOP）继承的特性。然而，Traits 真的有那么神奇么？难道真的能对 PHP 开发有所促进么？还是败絮其中呢？ PHP 的 Traits 是个祸害 从表面上来看，由于它可以降低整个应用中代码的复用成本而受到了非常强烈的支持。此外，它仍然可以帮你提高代码的可维护性，并看起来更简洁。 尽管 Traits 是那么的受欢迎，但是许多高级程序员却担心将来的情况并不会像当初设计的那样。高级程序员 Anthony Ferrara 担心它将会变成下一代被滥用的功能，像 evel 和 constants 那样。但在此之前，Anthony 曾提出了一个有趣的观点：Traits 其实是一个没有 state 的 Mixins 的具体集合。PHP 中的 Traints 支持 state 的使用。所以，PHP 的 Traints 实际就是 Mixins。这个简单的观点说明了 PHP Traits 的最终真实的意图，其实就是“挂着羊皮卖狗肉”。更不用解释为什么会以 Mixins 的形式，而不是以全球公认的无 state 的 Mixins 形式来处理（很抱歉，我都没明白是啥意思，看来还得深入了解下）。 Anthony 继续讲到，使用 Traints<div class="read-more"><a class="btn read-more-btn" href="https://blog.ihuxu.com/php-traits-good-or-bad/">Read More</a></div>]]></description>
		
					<wfw:commentRss>https://blog.ihuxu.com/php-traits-good-or-bad/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
