<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[PHP SPL笔记之offsetSet等相关函数了解备案。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Tue, 19 Mar 2013 10:13:51 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	SPL里有好多好的东西，但用的人相对较少甚至都想不起来，我在一个ko里就看到一个，offsetSet示例：<br/>代码：<br/><textarea name="code" class="php" rows="15" cols="100">
 $object-&gt;offsetSet($key, $value);
</textarea><br/>-----------------------------------------------------------------------------------------------------------------------------------------<br/>该SPL函数介绍：<br/>&nbsp;&nbsp;/**<br/>&nbsp;&nbsp; * Sets the value at the specified index to newval<br/>&nbsp;&nbsp; * @link http://www.php.net/manual/en/arrayobject.offsetset.php<br/>&nbsp;&nbsp; * @param index mixed &lt;p&gt;<br/>&nbsp;&nbsp; * The index being set.<br/>&nbsp;&nbsp; * &lt;/p&gt;<br/>&nbsp;&nbsp; * @param newval mixed &lt;p&gt;<br/>&nbsp;&nbsp; * The new value for the index.<br/>&nbsp;&nbsp; * &lt;/p&gt;<br/>&nbsp;&nbsp; * @return void <br/>&nbsp;&nbsp; */<br/>&nbsp;&nbsp;public function offsetSet ($index, $newval) &#123;&#125;<br/><textarea name="code" class="php" rows="15" cols="100">
* offsetSet($offset, $value)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This method is used to set a value within the object, 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;you can throw an exception from this function for a 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read-only collection.

</textarea><br/><br/>做下实际的相关SPL函数的测试，也就是相当于可以对一个对象进行添加属性，如类变量，数组等，同时提供相关的操作函数像操作数组一样对类对象进行操作里面的变量，带来了相当方便和灵活性，实践如下：<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
class Example &#123;
&nbsp;&nbsp;&nbsp;&nbsp;public $property = &#039;prop:public&#039;;
&#125;
$Eggobj = new Example();
$arrayobj = new ArrayObject($Eggobj);
$arrayobj-&gt;offsetSet(4, &#039;four&#039;);
$arrayobj-&gt;offsetSet(&#039;group&#039;, array(&#039;g1&#039;, &#039;g2&#039;));
print_r($arrayobj);//打印这个对象出来
//直接访问经offsetset添加后的对象
$objGrp = $Eggobj-&gt;property;
$objGrp2 = $Eggobj-&gt;group;
print_r($objGrp);
print_r($objGrp2);
//上面是可以打印出来的，但是4这样的整数就不行，会出错，得用这个SPL提供的新函数来做，如下：
var_dump($arrayobj-&gt;offsetGet(4)); //four
//你还可以查看该键值是否存在，用SPL提供的函数
var_dump($arrayobj-&gt;offsetExists(&#039;notfound&#039;)); //bool(false)

//对null在offsetset里的测试
$arrayobj = new ArrayObject(array(&#039;zero&#039;,&#039;one&#039;));
$arrayobj-&gt;offsetSet(null, &#039;last&#039;);//这样变成了在原来数组的后面继续添加last： ArrayObject Object([storage:ArrayObject:private]=&gt;Array([0]=&gt;zero[1]=&gt;one[2]=&gt;last))
print_r($arrayobj);
?&gt;
</textarea><br/><br/>offsetSet相关函数：<br/>http://www.ruanyifeng.com/blog/2008/07/php_spl_notes.html<br/>更加有助于理解的Url：<br/>http://www.mjplay.com.cn/php/fun/arrayobject.offsetset.html<br/>http://hi.baidu.com/gwsshoddxvcmnte/item/deecccdffb539d1420e2505a<br/>关于SPL的更多笔记，这个百度空间的兄弟写得较多了，如下Url：<br/>PHP SPL，遗落的宝石:http://hi.baidu.com/gwsshoddxvcmnte/item/288a08c477656203c610b25b<br/>PHP SPL 笔记:http://hi.baidu.com/gwsshoddxvcmnte/item/df0239c554dcc52fe80f2e5a<br/>PHP SPL 笔记2:http://hi.baidu.com/gwsshoddxvcmnte/item/deecccdffb539d1420e2505a<br/>PHP SPL 笔记3:http://hi.baidu.com/gwsshoddxvcmnte/item/51d9eef4b33562e41a111f5a<br/>PHP SPL 笔记4:http://hi.baidu.com/gwsshoddxvcmnte/item/039da3012f740e096d90485e
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP SPL笔记之offsetSet等相关函数了解备案。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>