<?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>Becomin&#039; Charles &#187; basic</title>
	<atom:link href="http://sexywp.com/tags/basic/feed" rel="self" type="application/rss+xml" />
	<link>http://sexywp.com</link>
	<description>Building another myself~~</description>
	<lastBuildDate>Fri, 27 Jan 2012 16:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>【边学边用】PHP5函数参数的按引用传递</title>
		<link>http://sexywp.com/php5-pass-param-by-ref.htm</link>
		<comments>http://sexywp.com/php5-pass-param-by-ref.htm#comments</comments>
		<pubDate>Fri, 26 Aug 2011 14:07:14 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[工作相关]]></category>
		<category><![CDATA[心得体会]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://sexywp.com/?p=454</guid>
		<description><![CDATA[PHP是支持引用的，但是关于一个变量什么时候是引用，什么时候是值，我脑子里总是迷迷糊糊的，所以，想用引用的时候，就会不自觉地在所有的地方加上&#038;符号，真的很累赘。为了缓解这个问题，我特意写了下面这个代码片段来增进自己的理解。起初，我对这个东西的理解是，对于对象来说，PHP5就是按照引用传递的。但是我现在想，可能事情不是这么一回事情。下面的代码片段中，$obj其实是A的对象的一个引用，可以理解成一个指针，函数参数$o，其实还是对$obj的拷贝，只是拷贝的是引用本身，也即，$o其实是$obj的拷贝，只是由于其拷贝了$obj，所以，$o也指向A的对象。两个指针指向一个地方，这也是为什么函数changeObj可以改变A的对象的原因。我想，这样大概从技术来说，会更加合理一点。

<span class="readmore"><a href="http://sexywp.com/php5-pass-param-by-ref.htm" title="【边学边用】PHP5函数参数的按引用传递">Keep Reading --- 315 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Flet-php5-support-readline.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Dedian 5的PHP包缺少readline支持</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fdeprecated-features-in-php-5-3.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 5.3.x中弃用的特性 Deprecated</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fphp-return.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips] PHP中return的用法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>PHP是支持引用的，但是关于一个变量什么时候是引用，什么时候是值，我脑子里总是迷迷糊糊的，所以，想用引用的时候，就会不自觉地在所有的地方加上&#038;符号，真的很累赘。为了缓解这个问题，我特意写了下面这个代码片段来增进自己的理解。起初，我对这个东西的理解是，对于对象来说，<a href="http://sexywp.com/tags/php" class="st_tag internal_tag" rel="tag" title="标签 PHP 下的日志">PHP</a>5就是按照引用传递的。但是我现在想，可能事情不是这么一回事情。下面的代码片段中，$obj其实是A的对象的一个引用，可以理解成一个指针，函数参数$o，其实还是对$obj的拷贝，只是拷贝的是引用本身，也即，$o其实是$obj的拷贝，只是由于其拷贝了$obj，所以，$o也指向A的对象。两个指针指向一个地方，这也是为什么函数changeObj可以改变A的对象的原因。我想，这样大概从技术来说，会更加合理一点。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">class</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">A</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$a</span><span style="color: Gray;">=</span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: Green;">public</span><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$b</span><span style="color: Gray;">=</span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$obj</span><span style="color: Gray;"> = </span><span style="color: Green;">new</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">A</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeObj</span><span style="color: Olive;">(</span><span style="color: #00008b;">$o</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$o</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">3</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$o</span><span style="color: Gray;">-&gt;</span><span style="color: Blue;">b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">5</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeObj</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$obj</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li></ol></div></div>
<p>执行结果如下：</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline">object(A)#1 (2) {</li>
<li>&nbsp; [&quot;a&quot;]=&gt;</li>
<li>&nbsp; int(1)</li>
<li>&nbsp; [&quot;b&quot;]=&gt;</li>
<li>&nbsp; int(1)</li>
<li>}</li>
<li>object(A)#1 (2) {</li>
<li>&nbsp; [&quot;a&quot;]=&gt;</li>
<li>&nbsp; int(3)</li>
<li>&nbsp; [&quot;b&quot;]=&gt;</li>
<li>&nbsp; int(5)</li>
<li>}</li></ol></div>
<p>然后再看一个普通变量的引用传递的例子，这个例子里面使用的是原生的整型变量，然后函数changeInt的函数声明里，也用一般方法声明参数，普通的调用，我们发现函数不能改变$x和$y的值，这符合我们的预期，但是第二个形式的调用，就是传参数时候，带上引用标志&#038;，结果我们发现，$x和$y的值也改变了，这是为什么呢，跟上面的例子是一个原因，函数的形式参数a和b其实是$x和$y的引用的拷贝，所以a和b也指向x和y，所以，a和b可以改变x和y的值。再看最下面的一种形式，这种是我认为的真正的按照引用传递参数。非常的绕乎对吧？我也觉得如此，确实太过灵活了。确实不利于学习和理解，代码也不容易维护，如果真的想用引用传递参数，推荐用最底下一种方式，明确告诉调用的人，这里其实是引用，千万别用changeInt(&#038;$x, &#038;$y);这种形式，这个代码散步在各处，将极难定位bug。</p>
<div class="hl-surround"><div class="hl-main"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li>&nbsp;<span style="color: Blue;">&lt;?php</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$x</span><span style="color: Gray;"> = </span><span style="color: Maroon;">1</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: #00008b;">$y</span><span style="color: Gray;"> = </span><span style="color: Maroon;">2</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: #00008b;">$a</span><span style="color: Gray;">, </span><span style="color: #00008b;">$b</span><span style="color: Olive;">)</span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">3</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">4</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">,</span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 1, $y = 2</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeInt</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, &amp;</span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 3, $y = 4</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Green;">function</span><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeIntByRef</span><span style="color: Olive;">(</span><span style="color: Gray;">&amp;</span><span style="color: #00008b;">$a</span><span style="color: Gray;">, &amp;</span><span style="color: #00008b;">$b</span><span style="color: Olive;">)</span><span style="color: Gray;"> </span><span style="color: Olive;">{</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$a</span><span style="color: Gray;"> = </span><span style="color: Maroon;">5</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;&nbsp; &nbsp; </span><span style="color: #00008b;">$b</span><span style="color: Gray;"> = </span><span style="color: Maroon;">6</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Olive;">}</span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">changeIntByRef</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">;</span></li>
<li><span style="color: Gray;">&nbsp; </span></li>
<li><span style="color: Gray;">&nbsp;</span><span style="color: Blue;">var_dump</span><span style="color: Olive;">(</span><span style="color: #00008b;">$x</span><span style="color: Gray;">, </span><span style="color: #00008b;">$y</span><span style="color: Olive;">)</span><span style="color: Gray;">; </span><span style="color: #ffa500;">//</span><span style="color: #ffa500;">$x = 5, $y = 6</span></li></ol></div></div>
<table class="wumii-related-items" cellspacing="0" cellpadding="2" border="0" width="100%" style="clear: both;">
    
    <tr>
        <td ><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Flet-php5-support-readline.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">Dedian 5的PHP包缺少readline支持</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fdeprecated-features-in-php-5-3.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">PHP 5.3.x中弃用的特性 Deprecated</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Flinux-commands-used-when-working.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">工作中常用的Linux命令集锦</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fphp-return.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">[Tips] PHP中return的用法</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td style="margin: 0 !important; padding: 0 !important; line-height: 20px !important;">
                    <img border="0" src="http://static.wumii.com/images/widget/widget_solidPoint.gif">
                    <a target="_blank" style="text-decoration: none !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fvideo-guide-to-use-yii-framework.htm&from=http%3A%2F%2Fsexywp.com%2Fphp5-pass-param-by-ref.htm">
                        <font size="-1" color="#333333" style="line-height: 1.65em; font-size: 12px !important;">视频教程：使用Yii框架开发Blog</font>
                    </a>
                </td>
            </tr>
    
    <tr>
        <td  align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/basic" title="basic" rel="tag">basic</a>, <a href="http://sexywp.com/tags/php" title="PHP" rel="tag">PHP</a>, <a href="http://sexywp.com/tags/usage" title="usage" rel="tag">usage</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/php5-pass-param-by-ref.htm/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>浅析WordPress中的Hook机制</title>
		<link>http://sexywp.com/try-to-explain-hook-in-wp.htm</link>
		<comments>http://sexywp.com/try-to-explain-hook-in-wp.htm#comments</comments>
		<pubDate>Wed, 11 Feb 2009 08:48:11 +0000</pubDate>
		<dc:creator>Charles</dc:creator>
				<category><![CDATA[Plugins Develop]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[basic]]></category>
		<category><![CDATA[develop]]></category>
		<category><![CDATA[filter]]></category>

		<guid isPermaLink="false">http://sexywp.com/try-to-explain-hook-in-wp.htm</guid>
		<description><![CDATA[Hook，既可以是动词，表示钩住，也可以是名词，表示钩子。在一个计算机程序中，Hook没有准确的并且合理的中文翻译，很多技术书籍文章，干脆就称之为“钩子”。

Hook机制（就是指Action和Filter的机制）正是WordPress能够有成千上万的插件支持的根源。

尽管我以前可能写过类似的文章来说明这个问题，但是我觉得这个东西是如此的重要，以至于如果你还没有明白什么是Hook，根本算不上走进了WP开发者的世界。又或者说，作为一个普通的玩家来说，深刻地理解Hook，能够帮助您走上DIY博客高速车道。

<span class="readmore"><a href="http://sexywp.com/try-to-explain-hook-in-wp.htm" title="浅析WordPress中的Hook机制">Keep Reading --- 1273 words totally</a></span><table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress 开发资源" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress 开发资源</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件：选项查看器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fplugin-options-inspector.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/31/10319696.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件：选项查看器</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（05）---WordPress 插件Actions" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-05.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（05）---WordPress 插件Actions</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>]]></description>
			<content:encoded><![CDATA[<p>Hook，既可以是动词，表示钩住，也可以是名词，表示钩子。在一个计算机程序中，Hook没有准确的并且合理的中文翻译，很多技术书籍文章，干脆就称之为“钩子”。</p>
<p>Hook机制（就是指Action和Filter的机制）正是WordPress能够有成千上万的插件支持的根源。</p>
<p>尽管我以前可能写过类似的文章来说明这个问题，但是我觉得这个东西是如此的重要，以至于如果你还没有明白什么是Hook，根本算不上走进了WP开发者的世界。又或者说，作为一个普通的玩家来说，深刻地理解Hook，能够帮助您走上DIY博客高速车道。</p>
<p>Hook这个东西，说难吧，很难，说容易吧，很容易，还真的不好解释。我不能保证每个看完这个文章的人能懂，知道个大概就行了。现在，我们开始。</p>
<p> <span id="more-296"></span>
<p>&#160;</p>
<p>我相信，很多像我一样的80后，会在高中的时候对编程感兴趣，你们很可能选择了一个东西作为入门，那就是Visual <a href="http://sexywp.com/tags/basic" class="st_tag internal_tag" rel="tag" title="标签 basic 下的日志">Basic</a>（VB）。在VB里面，编程变成了一件非常容易的事情，画一个界面，然后这个界面上的元素会在某个事件发生的时候，触发一个函数，在这个函数里，写好你要做的事情，一个Windows桌面应用就完成了。</p>
<p>这种编程的模型叫做事件驱动。你们一定会写一堆叫做OnButtonClick，OnSomethingDosth之类的Sub，具体的意思，就是说，当一个按钮按下，这个事情发生的时候，执行OnButtonClick这个Sub里面的代码。Ok，我想说的就是，在WP里面，就是一种很类似的东西，一个插件的代码，就好比是OnButtonClick这一类Sub里面的代码，而我们的主角hook（可能是一个action，也可能是一个filter，比如post_content，又比如wp_head），就是一个能够触发那段代码的事件，一旦发生，插件就会开始运行。希望到这里，很多学过VB的朋友能有个认识了。</p>
<p>&#160;</p>
<p>接着，时代发展了，OO，也即面向对象大行其道了。学OO，就不得不学一点设计模式了，否则，怎么敢说自己在面向对象呢？如果你碰巧看到过一个模式叫Observer的，那么我愚蠢地以为，可以从一定程度上解释hook机制。把整个WP，看作是一个对象，这个对象最终要打印一个网页出来，这个网页会按照PHP代码的先后顺序，一块一块生成，每个插件都分别是一个对象，非常关心它自己要处理的那一小块网页，它们就是各自关心的那一小块网页的观察者们。在WP初始化的时候，这些插件们就把自己添加到观察者的队列里面（即add_filter或者add_<a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">action</a>），而它们观察WP内部的这个窗口，就是action或者filter，WP在执行到特定的时候，就会通知这些插件，某个事情发生了（即apply_filters和do_<a href="http://sexywp.com/tags/action" class="st_tag internal_tag" rel="tag" title="标签 action 下的日志">action</a>）。</p>
<p>&#160;</p>
<p>抽象过后，来一点形象的东西。我又要使用我那不着边际的比喻了。想象一根电线，上面串连着一个接一个的插座。每个插件就是一个小家电，有一个插销，他们被各自地插到了合适自己的那个插座上。然后，电流从这个电线的一头流入，每经过一个插座，这个插座上连接着的电器就开始运转了。所有电器都通电运转了一遍以后，电闸关上了。Ok，这些插座，就好像是hook，有的是action形状的，有的是filter形状的，但是本质上就是插座。</p>
<p>&#160;</p>
<p>好了，我已经废了很多的唇舌了，我心里很清楚，结果可能是这样的，不理解的人，依旧不理解，理解的人，不用看就理解。虽然是这样，我还是执着地想要尝试着解释一下，因为我后面要写一个介绍Hybrid的文章，这个主题框架里面遍布着action和filter，如果不理解这个东西，无论如何也不可能用好Hybrid，同样，要说清Hybrid这个东西，无论如何也躲不过地要说一下hook。毕竟我还是想受人以渔的。</p>
<table class="wumii-related-items" cellspacing="0" cellpadding="3" border="0"  style="clear: both;">
    
    <tr>
        <td colspan="5"><b><font size="-1"  style="display: block !important; padding: 20px 0 5px !important;">您可能也喜欢：</font></b></td>
    </tr>
    
        <tr>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important;">
                    <a target="_blank" title="使用NetBeans IDE 6.5作为WordPress的开发环境" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fuse-netbeans-to-develop-wp.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/06/02/10636076.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">使用NetBeans IDE 6.5作为WordPress的开发环境</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress 开发资源" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fwordpress-developer-resource.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress 开发资源</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件开发实例--（01）" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Freal-wp-plugins-01.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/22/9193527.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件开发实例--（01）</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="WordPress插件：选项查看器" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fplugin-options-inspector.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/site_images/2011/05/31/10319696.png" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">WordPress插件：选项查看器</font>
                    </a>
                </td>
                <td width="86" valign="top" style="padding: 5px !important; margin: 0 !important; border-left: 1px solid #DDDDDD !important;">
                    <a target="_blank" title="插件开发全攻略（05）---WordPress 插件Actions" style="text-decoration: none !important; cursor: pointer !important;" href="http://app.wumii.com/ext/redirect.htm?url=http%3A%2F%2Fsexywp.com%2Fhow-to-write-a-wp-plugin-05.htm&from=http%3A%2F%2Fsexywp.com%2Ftry-to-explain-hook-in-wp.htm">
                        <img style="margin: 0 !important; padding: 2px !important; border: 1px solid #DDDDDD !important; width: 80px !important; height: 80px !important;" src="http://static.wumii.com/images/blogWidget/wordpress_default.gif" width="80px" height="80px" /><br />
                        <font size="-1" color="#333333" style="display: block !important; line-height: 15px !important; width: 86px !important; font: 12px/15px arial !important; height: 45px !important; margin: 3px 0 0 0 !important; padding: 0 !important; overflow: hidden !important;">插件开发全攻略（05）---WordPress 插件Actions</font>
                    </a>
                </td>
        </tr>
    
    <tr>
        <td colspan="5" align="right">
            <a style="text-decoration: none !important;" href="http://www.wumii.com/widget/relatedItems.htm" target="_blank" title="无觅相关文章插件">
                <font size="-1" color="#bbbbbb" style="display: block !important; font-family: arial !important; padding: 5px 0 !important; font-size: 12px !important; color: #bbb !important;">无觅</font>
            </a>
        </td>
    </tr>
</table>
	标签：<a href="http://sexywp.com/tags/action" title="action" rel="tag">action</a>, <a href="http://sexywp.com/tags/basic" title="basic" rel="tag">basic</a>, <a href="http://sexywp.com/tags/develop" title="develop" rel="tag">develop</a>, <a href="http://sexywp.com/tags/filter" title="filter" rel="tag">filter</a>, <a href="http://sexywp.com/tags/wordpress" title="WordPress" rel="tag">WordPress</a><br />
]]></content:encoded>
			<wfw:commentRss>http://sexywp.com/try-to-explain-hook-in-wp.htm/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

