<?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>dev.iordanov.net</title>
	<atom:link href="http://dev.iordanov.net/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.iordanov.net</link>
	<description></description>
	<lastBuildDate>Sun, 31 May 2009 18:07:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flash player linux and unicode.</title>
		<link>http://dev.iordanov.net/archives/15</link>
		<comments>http://dev.iordanov.net/archives/15#comments</comments>
		<pubDate>Sun, 31 May 2009 17:52:22 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[flex]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=15</guid>
		<description><![CDATA[Writing not english characters in swf applications under linux is a well known problem. These days I had some spare time to inspect it and try to fix it. So far I&#8217;ve a solution. I don&#8217;t know if this one is the best one or if there is a better way but I&#8217;m not an [...]]]></description>
			<content:encoded><![CDATA[<p>Writing not english characters in swf applications under linux is a <a href="http://bugs.adobe.com/jira/browse/FP-40" target="_blank">well known problem</a>. These days I had some spare time to inspect it and try to fix it. So far I&#8217;ve a solution. I don&#8217;t know if this one is the best one or if there is a better way but I&#8217;m not an expert in flash/flex development. The idea is to replace characters that came from flash player by their original characters using their code. eg. “193” with “а” (а is in Cyrillic) and so on. I know this will fix the problem for specified language (Bulgarian in this case), but will not fix it in general, so I decided to make something like a character map and load replacements dynamically. I use JSON for characters map. Here is an example file:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;193&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;а&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;194&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;б&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;215&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;в&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;199&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;г&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;196&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;д&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;197&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;е&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;214&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ж&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;218&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;з&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;201&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;и&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;202&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;й&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;203&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;к&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;204&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;л&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;205&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;м&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;206&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;н&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;207&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;о&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;208&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;п&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;210&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;р&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;211&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;с&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;212&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;т&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;213&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;у&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;198&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ф&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;200&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;х&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;195&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ц&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;222&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ч&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;219&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ш&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;221&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;щ&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;216&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ь&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;223&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ъ&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;192&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ю&quot;</span><span style="color: #339933;">,</span>
<span style="color: #3366CC;">&quot;209&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;я&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and the code that reads this file and replaces characters:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript">package net.<span style="color: #006600;">iordanov</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Cyrillic <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0066CC;">import</span> com.<span style="color: #006600;">adobe</span>.<span style="color: #006600;">serialization</span>.<span style="color: #006600;">json</span>.<span style="color: #006600;">JSON</span>;
        <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">http</span>.<span style="color: #006600;">HTTPService</span>;
        <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">ResultEvent</span>;
        <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">rpc</span>.<span style="color: #006600;">events</span>.<span style="color: #006600;">FaultEvent</span>;
        <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
&nbsp;
        <span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:<span style="color: #0066CC;">Object</span>; 
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> loadCharMap<span style="color: #66cc66;">&#40;</span>file:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> service:HTTPService = <span style="color: #000000; font-weight: bold;">new</span> HTTPService<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            service.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;result&quot;</span>, processJson<span style="color: #66cc66;">&#41;</span>;
            service.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;fault&quot;</span>, failure<span style="color: #66cc66;">&#41;</span>;
            service.<span style="color: #0066CC;">url</span> = file;
            service.<span style="color: #0066CC;">send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> processJson<span style="color: #66cc66;">&#40;</span>event:ResultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #0066CC;">data</span> = JSON.<span style="color: #006600;">decode</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #006600;">result</span>.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
&nbsp;
        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> failure<span style="color: #66cc66;">&#40;</span>event:FaultEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
        <span style="color: #66cc66;">&#123;</span>
            Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span>event.<span style="color: #0066CC;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> correctLinux<span style="color: #66cc66;">&#40;</span>str:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">String</span>
        <span style="color: #66cc66;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> char:<span style="color: #0066CC;">String</span>;
            <span style="color: #000000; font-weight: bold;">var</span> charCode:<span style="color: #0066CC;">Number</span>;
            <span style="color: #000000; font-weight: bold;">var</span> ret:<span style="color: #0066CC;">String</span> = <span style="color: #ff0000;">&quot;&quot;</span>;
&nbsp;
            <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">0</span>; i<span style="color: #66cc66;">&lt;</span>str.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                char = str.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
                charCode = str.<span style="color: #0066CC;">charCodeAt</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span>charCode<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
                    ret += <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span>charCode<span style="color: #66cc66;">&#93;</span>;
                <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
                    ret +=char;
                <span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span>
            <span style="color: #b1b100;">return</span> ret;
        <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>An example mxml file witch tests the code above:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="font-weight: bold; color: black;">?&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">layout</span>=<span style="color: #ff0000;">&quot;absolute&quot;</span> <span style="color: #000066;">creationComplete</span>=<span style="color: #ff0000;">&quot;loadLang()&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:Script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">        import net.iordanov.Cyrillic;</span>
<span style="color: #339933;">        import mx.rpc.events.ResultEvent;</span>
<span style="color: #339933;">        import mx.events.StyleEvent;</span>
&nbsp;
<span style="color: #339933;">        private function fixLinux(event:Event):void {</span>
<span style="color: #339933;">            text1.text = Cyrillic.correctLinux(text1.text);</span>
<span style="color: #339933;">        }</span>
&nbsp;
<span style="color: #339933;">        private function loadLang():void</span>
<span style="color: #339933;">        {</span>
<span style="color: #339933;">            Cyrillic.loadCharMap(&quot;http://dev.iordanov.net/flex/lang/bg.js&quot;);</span>
<span style="color: #339933;">        }</span>
<span style="color: #339933;">        ]]&gt;</span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;mx:TextInput</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;text1&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">change</span>=<span style="color: #ff0000;">&quot;fixLinux(event)&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/mx:Application<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>and simple html to load this swf application.</p>

<div class="wp_syntax"><div class="code"><pre>&lt;object width=&quot;550&quot; height=&quot;400&quot;&gt;
  &lt;param name=&quot;movie&quot; value=&quot;somefilename.swf&quot; /&gt;
  &lt;param name=&quot;wmode&quot; value=&quot;transparent&quot; /&gt; 
  &lt;embed src=&quot;cyrillic.swf&quot; width=&quot;550&quot; height=&quot;400&quot; wmode=&quot;transparent&quot;&gt;&lt;/embed&gt;
&lt;/object&gt;</pre></div></div>

<p>Note that wmode must be set to  transparent. In other case (I don&#8217;t know why, as I say I&#8217;m not an expert in flash/flex development) user must hold Ctrl key pressed while typing.</p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=Flash%20player%20linux%20and%20unicode.&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F15"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Flash player linux and unicode.";
		a2a_linkurl="http://dev.iordanov.net/archives/15";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/15/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xdebug configuration</title>
		<link>http://dev.iordanov.net/archives/11</link>
		<comments>http://dev.iordanov.net/archives/11#comments</comments>
		<pubDate>Mon, 27 Oct 2008 11:15:27 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=11</guid>
		<description><![CDATA[I&#8217;m going to post my xdebug config file because when I&#8217;m installing new developer machine (not so often &#8230; may be several times in year ) I usually have to search for some basic configuration and copy/paste/change it. It took me some time so I prefer to have it in my blog.

#change this
zend_extension=/usr/lib/php5/20060613+lfs/xdebug.so
&#160;
&#91;debug&#93;
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
&#160;
; [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to post my xdebug config file because when I&#8217;m installing new developer machine (not so often &#8230; may be several times in year ) I usually have to search for some basic configuration and copy/paste/change it. It took me some time so I prefer to have it in my blog.</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#change this</span>
<span style="color: #007800;">zend_extension=</span><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>php5<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">20060613</span>+lfs<span style="color: #000000; font-weight: bold;">/</span>xdebug.so
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>debug<span style="color: #7a0874; font-weight: bold;">&#93;</span>
; Remote settings
xdebug.<span style="color: #007800;">remote_autostart=</span>off
xdebug.<span style="color: #007800;">remote_enable=</span>on
xdebug.<span style="color: #007800;">remote_handler=</span>dbgp
xdebug.<span style="color: #007800;">remote_mode=</span>req
xdebug.<span style="color: #007800;">remote_host=</span>localhost
xdebug.<span style="color: #007800;">remote_port=</span><span style="color: #000000;">9000</span>
&nbsp;
; General
xdebug.<span style="color: #007800;">auto_trace=</span>on
xdebug.<span style="color: #007800;">collect_includes=</span>on
xdebug.<span style="color: #007800;">collect_params=</span>off
xdebug.<span style="color: #007800;">collect_return=</span>off
xdebug.<span style="color: #007800;">default_enable=</span>on
xdebug.<span style="color: #007800;">extended_info=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">manual_url=</span>http:<span style="color: #000000; font-weight: bold;">//</span>www.php.net
xdebug.<span style="color: #007800;">show_local_vars=</span><span style="color: #000000;">0</span>
xdebug.<span style="color: #007800;">show_mem_delta=</span><span style="color: #000000;">0</span>
xdebug.<span style="color: #007800;">max_nesting_level=</span><span style="color: #000000;">100</span>
;xdebug.<span style="color: #007800;">idekey=</span>
&nbsp;
; Trace options
xdebug.<span style="color: #007800;">trace_format=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">trace_output_dir=</span><span style="color: #000000; font-weight: bold;">/</span>tmp
xdebug.<span style="color: #007800;">trace_options=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">trace_output_name=</span>crc32
&nbsp;
; Profiling
xdebug.<span style="color: #007800;">profiler_append=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">profiler_enable=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">profiler_enable_trigger=</span><span style="color: #000000;">1</span>
xdebug.<span style="color: #007800;">profiler_output_dir=</span><span style="color: #000000; font-weight: bold;">/</span>tmp
xdebug.<span style="color: #007800;">profiler_output_name=</span>trace.<span style="color: #000000; font-weight: bold;">%</span>c</pre></div></div>

<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=xdebug%20configuration&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F11"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="xdebug configuration";
		a2a_linkurl="http://dev.iordanov.net/archives/11";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extjs rating extension</title>
		<link>http://dev.iordanov.net/archives/10</link>
		<comments>http://dev.iordanov.net/archives/10#comments</comments>
		<pubDate>Sat, 06 Sep 2008 08:28:19 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[extjs]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=10</guid>
		<description><![CDATA[Lately i was playing with extjs and i created an extension for rating. The extension itself has 2 components. The first one is the visual one. It&#8217;s a kind of slider with some modifications. It&#8217;s usage is the same as a slider&#8217;s. The second component is a form field that holds the value of the [...]]]></description>
			<content:encoded><![CDATA[<p>Lately i was playing with <a href="http://www.extjs.com">extjs</a> and i created an extension for rating. The extension itself has 2 components. The first one is the visual one. It&#8217;s a kind of <a href="http://extjs.com/deploy/dev/docs/?class=Ext.Slider">slider</a> with some modifications. It&#8217;s usage is the same as a slider&#8217;s. The second component is a form field that holds the value of the first one in a hidden input flield. The input element takes an extra parameter called starConfig and this parameter is passed to the constructor of the first component.</p>
<p>The number of stars is calculated dynamically and it&#8217;s equal to maxValue/increment<br />
for example</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript"><span style="color: #009900;">&#123;</span>
    minValue<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
    maxValue<span style="color: #339933;">:</span> <span style="color: #CC0000;">100</span>
    increment<span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This will give us 10 stars and each star increases the value of the hidden field by 10. By default increment = 1 and maxValue = 5</p>
<p>you can see demo <a href="http://dev.iordanov.net/ext/examples/starslider/slider.html">here</a> and download the extension <a href="http://dev.iordanov.net/starslider.tar.gz">here</a></p>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=Extjs%20rating%20extension&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F10"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="Extjs rating extension";
		a2a_linkurl="http://dev.iordanov.net/archives/10";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/10/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>php 5.3: notes about closures and lambda functions</title>
		<link>http://dev.iordanov.net/archives/9</link>
		<comments>http://dev.iordanov.net/archives/9#comments</comments>
		<pubDate>Fri, 18 Jul 2008 20:11:12 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=9</guid>
		<description><![CDATA[Few days ago a friend of mine told me that php will support closures and lambda functions.
You can find example code and explanation about lambda functions and closures in php&#8217;s wiki
I just want to drop a few notes.
1. there are (still) no lambda classes, but I hope in next releases they will be implemented.
2. lambda [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago a friend of mine told me that php will support closures and lambda functions.<br />
You can find <a href="http://wiki.php.net/rfc/closures">example code and explanation about lambda functions and closures</a> in <a href="http://wiki.php.net/">php&#8217;s wiki</a></p>
<p>I just want to drop a few notes.<br />
1. there are (still) no lambda classes, but I hope in next releases they will be implemented.<br />
2. lambda function definitions must end with &#8220;;&#8221;. I think it&#8217;s important because I made a parse error first time <img src='http://dev.iordanov.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
3. &#8220;By default, all imported variables are copied as values into the closure. This makes it impossible for a closure to modify the variable in the parent scope. By prepending an &#038; in front of the variable name in the use declaration, the variable is imported as a reference instead. In that case, changes to the variable inside the closure will affect the outside scope.&#8221;<br />
Well this is actually not correct. Objects are passed by reference. If you need to use objects in closures you still have to use clone.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> foo
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000033;">$bar</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000033;">$foo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> foo<span style="color: #339933;">;</span>
<span style="color: #000033;">$lambda</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> use <span style="color: #009900;">&#40;</span><span style="color: #000033;">$foo</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Imported variable:&quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$lambda</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;Original variable: &quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$foo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bar</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>result is:</p>
<blockquote><p>
Imported variable:5<br />
Original variable: 6
</p></blockquote>
<p>4. closures combined with Reflection allow calling private method of a given object.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Foo <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #990000;">static</span> <span style="color: #000000; font-weight: bold;">function</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;I'm private method<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000033;">$class</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Foo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$method</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$class</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$closure</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$method</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getClosure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$closure</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Output is:</p>
<blockquote><p>
I&#8217;m private method
</p></blockquote>
<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=php%205.3%3A%20notes%20about%20closures%20and%20lambda%20functions&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F9"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="php 5.3: notes about closures and lambda functions";
		a2a_linkurl="http://dev.iordanov.net/archives/9";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/9/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>extending Zend_Db_Table to create NestedSet models</title>
		<link>http://dev.iordanov.net/archives/8</link>
		<comments>http://dev.iordanov.net/archives/8#comments</comments>
		<pubDate>Sun, 13 Jul 2008 12:00:09 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=8</guid>
		<description><![CDATA[Last days I’ve been trying to customize Zend&#8217;s Framework. My goal is to create simpler models. Currently I’m making some db models that handle stuff around wide used designs. Such design is the Nested Set model. It is an adjacent list realized in SQL as a tree. You can find a good introduction to nested [...]]]></description>
			<content:encoded><![CDATA[<p>Last days I’ve been trying to customize Zend&#8217;s Framework. My goal is to create simpler models. Currently I’m making some db models that handle stuff around wide used designs. Such design is the Nested Set model. It is an adjacent list realized in SQL as a tree. You can find a <a href="http://dev.mysql.com/tech-resources/articles/hierarchical-data.html" target="_blank">good introduction to nested sets</a> at <a href="http://dev.mysql.com/" target="_blank">mysql developer zone</a>.</p>
<p>Now let&#8217;s create a basic table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sql"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> nested_table <span style="color: #66cc66;">&#40;</span>
    <span style="color: #ff0000;">`nested_table_id`</span> int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span><span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">`nested_table_left`</span> int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">`nested_table_right`</span> int <span style="color: #993333; font-weight: bold;">UNSIGNED</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span>
    <span style="color: #ff0000;">`nested_table_name`</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>And now let&#8217;s create a model that will work with this table.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> NestedTable <span style="color: #000000; font-weight: bold;">extends</span> Custom_Db_Nestedset <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">//basic mapping</span>
    protected <span style="color: #000033;">$_name</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;nested_table&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//table name</span>
    protected <span style="color: #000033;">$_primary</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;nested_table_id&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//primary key</span>
    protected <span style="color: #000033;">$_left</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;nested_table_left&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//left column</span>
    protected <span style="color: #000033;">$_right</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;nested_table_right&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//right column</span>
    protected <span style="color: #000033;">$_toString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;nested_table_name&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//used when retrieving tree. if not set primary key will be used</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And that&#8217;s it. Now we have class that work as a nested set. Here is example controller.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> NestedController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> testAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$table</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> NestedTable<span style="color: #339933;">;</span>
        <span style="color: #000033;">$root</span>  <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createRoot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//creating root node.</span>
        <span style="color: #000033;">$node1</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertAsFirstChildOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$root</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//insert as first child of root category.</span>
        <span style="color: #000033;">$node2</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertAsNextSiblingOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$node1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//insert node next to given node. In our case next to node1.</span>
        <span style="color: #000033;">$node3</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertAsPrevSiblingOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$node2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//insert node before given node.</span>
        <span style="color: #000033;">$node4</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertAsLastChildOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$root</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//insert node as last child of root category.</span>
&nbsp;
        <span style="color: #000033;">$node2_1</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertAsFirstChildOf</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$node2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//go one level deeper.</span>
        <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deleteNode</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$node2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// delete node2 and his childs.</span>
&nbsp;
        <span style="color: #000033;">$table</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTree</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//retrieve full tree (subtrees are still not supported)</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and here is the nested set class.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/**
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license
 *
 * @category  Custom
 * @package  Custom_Db
 * @subpackage Nestedset
 * @copyright Copyright (c) 2008 Ivan Iordanov &lt;ivan@iordanov.net&gt;
 * @version  $Id: Nestedset.php 2008-06-06
 * @see    http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
 */</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/**
 * @see Zend_Db_Table
 */</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Db/Table.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/**
 * Class for SQL Nested set interface.
 *
 * @category  Custom
 * @package  Custom_Db
 * @subpackage Nestedset
 * @copyright Copyright (c) 2008 Ivan Iordanov (http://dev.iordanov.net)
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Custom_Db_Nestedset <span style="color: #000000; font-weight: bold;">extends</span> Zend_Db_Table
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * left column in nested table
    *
    * @var String
    */</span>
    protected <span style="color: #000033;">$_left</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * right column in nested table
    *
    * @var String
    */</span>
    protected <span style="color: #000033;">$_right</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Column to be retrieved with getTree method
    * If not set primary key will be used.
    *
    * @var String
    */</span>
    protected <span style="color: #000033;">$_toString</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Additional data to be inserted.
    *
    * @var Array
    */</span>
    <span style="color: #000000; font-weight: bold;">private</span>  <span style="color: #000033;">$_insertData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * constructor
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_toString<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_toString <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_primary<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Additional data to be inserted
    *
    * @param array
    * @access public
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setInsertData<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #000033;">$data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Retrieve whole tree
    *
    * @access public
    * @return array
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTree<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//todo: add custom node</span>
        <span style="color: #000033;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
            SELECT COUNT(parent.{$this-&gt;_primary[1]}) - 1 as depth, node.{$this-&gt;_toString}
            FROM {$this-&gt;_name} AS node, {$this-&gt;_name} AS parent
            WHERE node.{$this-&gt;_left}
            BETWEEN parent.{$this-&gt;_left}
            AND parent.{$this-&gt;_right}
            GROUP BY node.{$this-&gt;_primary[1]}
            ORDER BY node.{$this-&gt;_left}
        &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$ret</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert node as first child
    *
    * @param int
    * @access public
    * @return int
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertAsFirstChildOf<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveData</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$right</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$left</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_right} = {$this-&gt;_right} + 2 WHERE {$this-&gt;_right} &gt; {$left}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_left} = {$this-&gt;_left} + 2 WHERE {$this-&gt;_left} &gt; {$left}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$left</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$left</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #339933;">,</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert node as last child
    *
    * @param int
    * @access public
    * @return int
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertAsLastChildOf<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveData</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$right</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$left</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_right} = {$this-&gt;_right} + 2 WHERE {$this-&gt;_right} &gt;= {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_left} = {$this-&gt;_left} + 2 WHERE {$this-&gt;_left} &gt; {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000033;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$right</span><span style="color: #339933;">,</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$right</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #339933;">,</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert node as next sibling of given node
    *
    * @param int
    * @access public
    * @return int
    * @throws Exception
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertAsNextSiblingOf<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveData</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$right</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$left</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$left</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Root node can't have siblings&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_right} = {$this-&gt;_right} + 2 WHERE {$this-&gt;_right} &gt; {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_left} = {$this-&gt;_left} + 2 WHERE {$this-&gt;_left} &gt; {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000033;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$right</span><span style="color: #cc66cc;">+1</span><span style="color: #339933;">,</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$right</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #339933;">,</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert node as prev sibling of given node
    *
    * @param int
    * @access public
    * @return int
    * @throws Exception
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> insertAsPrevSiblingOf<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveData</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$right</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$left</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$left</span> <span style="color: #339933;">===</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Root node can't have siblings&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_right} = {$this-&gt;_right} + 2 WHERE {$this-&gt;_right} &gt; {$left}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_left} = {$this-&gt;_left} + 2 WHERE {$this-&gt;_left} &gt;= {$left}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000033;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$left</span><span style="color: #339933;">,</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right <span style="color: #339933;">=&gt;</span> <span style="color: #000033;">$left</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #339933;">,</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Delete node with it's child(s) and return affected rows
    *
    * @param int
    * @access public
    * @return int
    */</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> deleteNode<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">retrieveData</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$right</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$left</span>  <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000033;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$width</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$right</span> <span style="color: #339933;">-</span> <span style="color: #000033;">$left</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$res</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM {$this-&gt;_name} WHERE {$this-&gt;_left} BETWEEN {$left} AND {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_right} = {$this-&gt;_right} - {$width} WHERE {$this-&gt;_right} &gt; {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_db<span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE {$this-&gt;_name} SET {$this-&gt;_left} = {$this-&gt;_left} - {$width} WHERE {$this-&gt;_left} &gt; {$right}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$res</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rowCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert root node
    *
    * @access public
    * @return int
    */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> createRoot<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000033;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_left <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_right <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #339933;">,</span> <span style="color: #000033;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_insertData<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/**
    * Insert node
    *
    * @param int
    * @access private
    * @return Zend_Db_Row
    */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> retrieveData<span style="color: #009900;">&#40;</span><span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000033;">$select</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_primary<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">' = ?'</span><span style="color: #339933;">,</span> <span style="color: #000033;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchRow</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=extending%20Zend_Db_Table%20to%20create%20NestedSet%20models&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F8"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="extending Zend_Db_Table to create NestedSet models";
		a2a_linkurl="http://dev.iordanov.net/archives/8";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/8/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>php magic __set and __get</title>
		<link>http://dev.iordanov.net/archives/6</link>
		<comments>http://dev.iordanov.net/archives/6#comments</comments>
		<pubDate>Sun, 15 Jun 2008 09:34:35 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=6</guid>
		<description><![CDATA[Last days I have a problem with php magic functions and specially with overloading. Here is an example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Container
&#123;
private $_data;
&#160;
public function __set&#40;$key, $value&#41;
&#123;
$this-&#62;_data&#91;$key&#93; = $value;
&#125;
&#160;
public function __get&#40;$key&#41;
&#123;
return $this-&#62;_data&#91;$key&#93;;
&#125;
&#160;
public function __isset&#40;$key&#41;
&#123;
return isset&#40;$this-&#62;_data&#91;$key&#93;&#41;;
&#125;
&#160;
public function __unset&#40;$key&#41;
&#123;
if &#40;$this-&#62;__isset&#40;$this-&#62;_data&#91;$key&#93;&#41;&#41;
unset&#40;$this-&#62;_data&#91;$key&#93;&#41;;
&#125;
&#125;

when you try to use this code with arrays for example:

1
2
3
4
$c = new Container;
$c-&#62;arr = array&#40;&#41;;
$c-&#62;arr&#91;'test'&#93; = 'test';
var_dump&#40;$c-&#62;arr&#91;'test'&#93;&#41;;

it rise a notice: [...]]]></description>
			<content:encoded><![CDATA[<p>Last days I have a problem with php magic functions and specially with overloading. Here is an example code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Container
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000033;">$_data</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #339933;">,</span> <span style="color: #000033;">$value</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __get<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __unset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>__isset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>when you try to use this code with arrays for example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php"><span style="color: #000033;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Container<span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>it rise a notice: Indirect modification of overloaded property Container::$arr has no effect.<br />
and $c1->arr['test'] is null instead of test.</p>
<p>a work around is first to get this array into a temporary variable, make changes you need and then set it again.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php"><span style="color: #000033;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Container<span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$tmpArr</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$tmpArr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$tmpArr</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>this one works as expected. Actually php interpreter seems to do same thing. Trying to get value if exists and change it. Problem is that when it takes this value there is no place to store it and rise this error. Trying to modify property in not existing array. Solution is to make this array available. Returning values by reference seems to work.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">class</span> Container
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000033;">$_data</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __set<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #339933;">,</span> <span style="color: #000033;">$value</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>__get<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __isset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">return</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __unset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>__isset<span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$this</span><span style="color: #339933;">-&gt;</span>_data<span style="color: #009900;">&#91;</span><span style="color: #000033;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now this code works as expected:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php"><span style="color: #000033;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Container<span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">arr</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=php%20magic%20__set%20and%20__get&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F6"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="php magic __set and __get";
		a2a_linkurl="http://dev.iordanov.net/archives/6";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/6/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SplFastArray</title>
		<link>http://dev.iordanov.net/archives/5</link>
		<comments>http://dev.iordanov.net/archives/5#comments</comments>
		<pubDate>Tue, 10 Jun 2008 19:07:01 +0000</pubDate>
		<dc:creator>ivan</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dev.iordanov.net/?p=5</guid>
		<description><![CDATA[Few days ago I&#8217;ve downloaded last version of php5.3 from snaps.php.net and I&#8217;ve made some tests with SplFastArray. Results are very strange for me:
here is result of last test I&#8217;ve made few minutes ago.
$ php fastarray.php
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
marker                 time index  [...]]]></description>
			<content:encoded><![CDATA[<p>Few days ago I&#8217;ve downloaded last version of php5.3 from snaps.php.net and I&#8217;ve made some tests with SplFastArray. Results are very strange for me:</p>
<p>here is result of last test I&#8217;ve made few minutes ago.</p>
<blockquote><p>$ php fastarray.php<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
marker                 time index            ex time         perct<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Start                  1213124261.36967200   &#8211;                0.00%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
simple array foreach   1213124261.57657300   0.20690083503723  13.10%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
fast array foreach     1213124261.89191900   0.31534600257874  19.96%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
simple array for       1213124262.36776400   0.47584509849548  30.12%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
fast array for         1213124262.94954500   0.58178091049194  36.82%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Stop                   1213124262.94959900   5.4121017456055E-5   0.00%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
total                  &#8211;                     1.5799269676208100.00%<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p></blockquote>
<p>and here is the source code I use for test:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000033;">$iterations</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000000</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SplFastArray<span style="color: #009900;">&#40;</span><span style="color: #000033;">$iterations</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$b</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000033;">$iterations</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000033;">$a</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$i</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$b</span><span style="color: #009900;">&#91;</span><span style="color: #000033;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$i</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Benchmark/Timer.php'</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Benchmark_Timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$b</span> <span style="color: #b1b100;">as</span> <span style="color: #000033;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000033;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMarker</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple array foreach'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$a</span> <span style="color: #b1b100;">as</span> <span style="color: #000033;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000033;">$v</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMarker</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fast array foreach'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span><span style="color: #000033;">$b</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMarker</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'simple array for'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000033;">$a</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000033;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMarker</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fast array for'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #000033;">$timer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p class="addtoany_share_save">
    <a name="a2a_dd" onmouseover="a2a_show_dropdown(this)" onmouseout="a2a_onMouseOut_delay()" href="http://www.addtoany.com/bookmark?sitename=dev.iordanov.net&amp;siteurl=http%3A%2F%2Fdev.iordanov.net%2F&amp;linkname=SplFastArray&amp;linkurl=http%3A%2F%2Fdev.iordanov.net%2Farchives%2F5"><img src="http://dev.iordanov.net/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" border="0" alt="Share/Save/Bookmark"/></a>
    <script type="text/javascript">
		a2a_linkname="SplFastArray";
		a2a_linkurl="http://dev.iordanov.net/archives/5";
				    </script>
    <script type="text/javascript" src="http://www.addtoany.com/menu/page.js"></script>

	</p>]]></content:encoded>
			<wfw:commentRss>http://dev.iordanov.net/archives/5/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
