<?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>Arnisoft &#187; Programming</title>
	<atom:link href="http://arnisoft.com/category/flash-flex/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://arnisoft.com</link>
	<description>Software Development  &#38; Networkadministration</description>
	<lastBuildDate>Wed, 13 Apr 2011 16:23:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP magic methods performance</title>
		<link>http://arnisoft.com/354/php-magic-methods-performance/</link>
		<comments>http://arnisoft.com/354/php-magic-methods-performance/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 17:42:16 +0000</pubDate>
		<dc:creator>devarni</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://arnisoft.com/?p=354</guid>
		<description><![CDATA[How is the performance of magic methods (__call, __get, __set, &#8230;)? Compared to direct method calls: bad. Here a short benchmark and the code I wrote for this benchmark (needs PHP 5.3): Method Call: 3.01 seconds Direct Access: 2.47 seconds Magic Method (__call) 5.32 seconds Magic Method (__get) 5.37 seconds define('ITERATIONS', 2000000); function doBenchmark($name, Closure [...]]]></description>
			<content:encoded><![CDATA[<h3>How is the performance of magic methods<br />
 (__call, __get, __set, &#8230;)?</h3>
<p>Compared to direct method calls: bad. Here a short benchmark and the code I wrote for this benchmark (needs PHP 5.3):</p>
<table>
<tr>
<td>Method Call:</td>
<td>3.01 seconds</td>
</tr>
<tr>
<td>Direct Access:</td>
<td>2.47 seconds</td>
</tr>
<tr>
<td>Magic Method (__call)</td>
<td>5.32 seconds</td>
</tr>
<tr>
<td>Magic Method (__get)</td>
<td>5.37 seconds</td>
</tr>
</tbody>
</table>
<pre name="code" class="php">define('ITERATIONS', 2000000);
    function doBenchmark($name, Closure $closure){
        $start = microtime(true);
        for ($i=0; $i < ITERATIONS; ++$i) {
            $closure();
        }
        $stop = microtime(true);
        echo "Test $name: " . ($stop - $start) . " seconds";
    }

    class Test{
        public $data = array("view" => "view", "test2" => "test2", "test3" =>"test3");

        public function getView(){
            return $this->data['view'];
        }

        public function __call($name, $arg){
           return $name=="_getView" ? $this->data['view'] : false;
        }

        public function __get($key){
            return array_key_exists($key, $this->data) ? $this->data[$key] : null;
        }
    }

    $t = new Test();
    doBenchmark("Methode Call", function(){
        global $t;
        $v = $t->getView();
    });

    doBenchmark("Direct Access", function(){
        global $t;
        $v = $t->data['view'];
    });

    doBenchmark("Magic Methode (__call)", function(){
        global $t;
        $v = $t->_getView();
    });

    doBenchmark("Magic Methode (__get)", function(){
        global $t;
        $v = $t->view;
    });
</pre>
<p>So, you get the picure <img src='http://arnisoft.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Don&#8217;t use magic methods as a replacement for a regular method if a direct access to a field or variable is possible. Magic methods are the sugar for dynamic created attributes (eg. for database objects) or if you don&#8217;t know the method/attribute while writing the code.</p>
<p><strong>Use magic methods only rarely</strong>.</p>
<p>The only special magic method you should use often: __autoload  <img src='http://arnisoft.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  It helps to load your needed classes on demand only when they are needed. If you use namespaces, here a short trick to load the name-mangled classes (the $path must of course be changed to your needs):</p>
<p><br class="spacer_" /></p>
<pre name="code" class="php">function __autoload($class) {
    $parts = explode('\\', $class);
    $class = end($parts);
    $path = __DIR__ . "/includes/"); //path for the includes

     require ($path . $class . ".php");
}
</pre>
<p>Happy coding <img src='http://arnisoft.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://arnisoft.com/354/php-magic-methods-performance/feed/lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash  symbols with Actionscript3 in Flex</title>
		<link>http://arnisoft.com/76/using-of-flash-symbols-in-flex/</link>
		<comments>http://arnisoft.com/76/using-of-flash-symbols-in-flex/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 00:11:59 +0000</pubDate>
		<dc:creator>devarni</dc:creator>
				<category><![CDATA[Flash & Flex]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[FlexBuilder]]></category>

		<guid isPermaLink="false">http://arnisoft.com/?p=76</guid>
		<description><![CDATA[The difference Don&#8217;t forget: Flash != Flex. Flex uses elements from Flash but is built on own classes. If Flash and Flex should play together we need a interface. MovieClip is a display object in Flash and UIComponent is a display object in Flex. But we can wrap a MovieClip into a UIComponent, so the [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><strong>The difference</strong></p>
<p>Don&#8217;t forget: Flash != Flex. Flex uses elements from Flash but is built on own classes. If Flash and Flex should play together we need a interface.<br />
<em>MovieClip</em> is a display object in Flash and <em>UIComponent</em> is a display object in Flex. But we can wrap a <em>MovieClip</em> into a <em>UIComponent</em>, so the Flex UIComponent becomes a container for our Flash MovieClip.<br />
Here both files, at first the MXML file:
</p>
<pre name="code" class="xml">
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="FlexApp.initApp()">

</mx:Application>
</pre>
</p>
<p>
And the Actionscript file with the class:
</p>
<pre name="code" class="js">

package {
	import mx.core.Application;
	import mx.core.UIComponent;
	import flash.display.MovieClip;

	/*****************************************************************
	 * File: FlexApp.as
	 *****************************************************************/

	public class FlexApp {
		private var _app:Application;

		public function FlexApp(app:Application) {
			_app=app;

			var btn:MovieClip=new BtnStop();
			var flexui:UIComponent=new UIComponent;
			flexui.addChild(btn);
			app.addChild(flexui);
		}

		static public function initApp():FlexApp {
			return new FlexApp(Application(Application.application));
		}

		public function get app():Application {
			return _app;
		}
	}
}
</pre>
</p>
<p><strong>How it works</strong></p>
<p><em>applicationComplete</em> in the MXML file is the eventhandler called from the application. Here we provide our handler, which must be a static member function of a class so it can be called later.</p>
<p><em>initApp()</em> creates our class and passes a application object to the constructor.</p>
<p>Inside the constructor we create the <em>MovieClip</em> from the imported Flash symbol &#8220;BtnStop&#8221; (this symbol comes from  a swc lib, created with Flash). Then we create a Flex <em>UIComponent</em> container and add our MovieClip as a child. The <em>UIComponent</em> can now be added as child of the Flex application.</p>
]]></content:encoded>
			<wfw:commentRss>http://arnisoft.com/76/using-of-flash-symbols-in-flex/feed/lang/en/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

