<?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>Andrew's Tech Musings</title>
	<atom:link href="http://andrewcurioso.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewcurioso.com</link>
	<description>Tech, Social Media, PHP, Opinions</description>
	<lastBuildDate>Tue, 09 Feb 2010 07:16:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A method called &#8216;delete&#8217; in Flex and AS3</title>
		<link>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/</link>
		<comments>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 05:26:30 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=137</guid>
		<description><![CDATA[You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a [...]]]></description>
			<content:encoded><![CDATA[<p>You are in for a headache if you have try to call a method or create a member variable with the name of a reserved word in Actionscript. It can lead to such fun situations as having variables called: insert; update; deleteSomething. Because calling the third variable &#8220;delete&#8221; may be logical but it is a reserved word so that is out of the question. It gets hairier when you don&#8217;t necessarily have control over the object format (such is often the case with remote calls). I ran into this today when trying to call the &#8220;node_delete&#8221; (or &#8220;node.delete&#8221;) method in Drupal via Services and AMFPHP. This is frustrating so I&#8217;m going to show two situations where you could run into this problem and how I fixed them.<br />
<span id="more-137"></span></p>
<h3>Situation #1: A variable named &#8220;new&#8221; in a dynamic class</h3>
<p>You are creating a dynamic object and you need to use a reserved word as a member variable name but you can&#8217;t.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var x:Object = new Object;
x.new = &quot;this doesn't work&quot;;
x['new'] = &quot;this works&quot;;
</pre>
<p></span><br />
The first method is a nice way to get <em>1084: Syntax error: expecting identifier before new</em> when you try to compile. Remove that line and use just the second one and you are all set. It is OK to mix and match access methods, as long as you never use dot notation for reserved words.</p>
<h3>Situation #2: A RPC method named delete</h3>
<p>You are making a remote call via the RemoteObject class (such as I was doing with Drupal) and you need to call a method named &#8220;delete&#8221; (or &#8220;new&#8221; for that matter). You naturally try this:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var ro:RemoteObject = new RemoteObject;
ro.endpoint = &quot;http://www.example.com/amfphp&quot;;
ro.delete( 1234 );
</pre>
<p></span><br />
You will be promptly greeted by the now familiar 1084 error when you try to compile and using a different notation won&#8217;t work. I&#8217;ll break the solution into multiple parts although it could just as easily be chained together:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: jscript;">
var op:AbstractOperation = ro.getOperation('delete');
op.send( 12345 );
</pre>
<p></span><br />
Incidentally the result of the &#8220;send&#8221; method is a AsyncToken object (the same object that &#8220;ro.delete()&#8221; would return if delete were not reserved) which can then be used to add responders.</p>
<p>There you have it. Two quick and easy ways to get around methods and properties with reserved words for names.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/07/a-method-called-delete-in-flex-and-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>5 things about PHP 5.3 that make me smile</title>
		<link>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/</link>
		<comments>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 03:41:08 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[early adopters]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=89</guid>
		<description><![CDATA[Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them [...]]]></description>
			<content:encoded><![CDATA[<p>Rest assured. Soon I will be writing &#8220;Things about PHP 5.3 that make me cringe&#8221; but for now I sing the praises of the latest release of PHP that that came out today. I&#8217;ve been playing with the new release for months and there are indeed many good things about it and many of them have been a long time coming.</p>
<p>The other day I was reading the release notes and I couldn&#8217;t help but smile.<br />
<span id="more-89"></span></p>
<h3>1. New native MySQL driver</h2>
<p>I&#8217;m saving the best for last. So bear with me. Lets get through the small grins before we get to the big toothy ones (or you can read ahead&#8230; you&#8217;re choice). PHP 5.3 ships with a new MySQL driver called mysqld. A database driver is responsible for making the actually connection from PHP to MySQL. The previous MySQL driver had some flaws. For one, it was license in a way that was not compatible with the PHP license. The new <em>MySQL Native Driver</em> has a more amicable license (which is big in the open source world). It also adds some experimental functionality including improved persistent connections. There is also a down side but that is for another post.</p>
<h3>2. Host specific PHP INI configurations</h3>
<p>I previously worked on a hosted CMS and web publishing tool that had dozens of virtual hosts but only one php.ini. The new functionality allows to section off your PHP configuration to have a different configuration for every host or file path. I haven&#8217;t tried this one yet so I&#8217;m not sure how well it works. Try it out for yourself. There is a comment on <a href="http://www.php.net/">PHP.net</a> right now saying that it only works for CGI PHP and not for the CLI implementation.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: plain;">
[HOST=example.com]
error_reporting = E_ALL
display_errors = On
</pre>
<p></span><br />
Example from the PHP documentation.</p>
<h3>3. Shortcut ternary operator</h3>
<p>I had never considered this before. However, this saves a lot of time for rather repetitive code. Consider these three identical code snipits.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
if ( $foo ) $x = $foo;
else $x = $bar;

$x = ( $foo ? $foo : $bar );
$x = ( $foo ?: $bar );
?&gt;
</pre>
<p></span></p>
<p>The third method is the new shortcut. It reads simply: &#8220;if foo than foo else bar.&#8221; I am still waiting for the first time for this to be useful. The biggest issue I see is that in the above example $foo cannot legitimately be anything that evaluates to false. As a result it is best used for variables that should be non-empty strings or non-zero numbers.</p>
<h3>4. Date math</h3>
<p>The DateTime class now has several new methods in it for dealing with date arithmetic. It puts an end to manually converting to timestamps and back to dates again. It works very simply:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
$date = new DateTime('2009-06-30 09:00:00');
$date-&gt;sub('P5D'); // Subtract five days
echo $data-&gt;diff( new DateTime() )-&gt;format('%d').' days ago';
?&gt;
</pre>
<p></span><br />
The new DateTime methods and the new DateInterval class (returned from and passed to math functions) aren&#8217;t very well documented because they are so new.<br />
It is worth noting that the format methods are different in the two classes. Intervals require a percentage (%) in front of placeholders. Watch out for that.</p>
<h3>5. Closures</h3>
<p>Closures are one of the best parts of PHP 5.3. At first I wasn&#8217;t very excited about them. I use closures constantly in Javascript but in a stateless HTTP request situation they appear less useful. But then I got into it. They are improved methods of dealing with lambda-functions. In other words, they are functions that are nameless and can be assigned to variables. In actuality they are classes.<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?phpi
$y = 10;
$x = function($number) use ( &amp;$y ) {
  return $number * $y;
};
$y = 100;
echo $x(8); // Output: 800
?&gt;
</pre>
<p></span><br />
This is the point at which a lot of PHP programmers would pause. Did I say they are classes? Since when can you call a class like it was a function? Since PHP 5.3 you can! . You do it by defining the &#8220;_invoke&#8221; magic method. Like so:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: php;">
&lt;?php
class testInvoke {
  public function __invoke( $x ) { echo &quot;Hello $x&quot;; }
};
$x = new TestInvoke();
echo $x('world'); // outputs &quot;Hello World&quot;
?&gt;
</pre>
<p></span><br />
This is by far one of the coolest new features in PHP 5.3. It opens a whole new world of possibilities for clean / manageable code.</p>
<h3>Bonus Things</h3>
<h4>5.1. New magic method for matching calls to static methods</h4>
<p>For a while now we have been able to define the magic method &#8220;__call&#8221; in our classes that will be executed if you try to call a method in a class instance that does not exist. Now the &#8220;__callStatic&#8221; method does the same thing only for methods of static classes.</p>
<h4>5.2. Late static binding</h4>
<p>Late static binding is a long time coming. In fact, this has tripped me up in several projects. In simplest terms late binding is waiting to determine what object a method or member variable belongs to until it is called. Late static binding in PHP, as its name indicates, applies this concept to static methods and members variables in PHP. The PHP.net website bests describes in on the <a href="http://us.php.net/lsb">manual page for late static binding</a>.</p>
<h4>5.3. E_DEPRECATED</h4>
<p>Here is a tip for everyone: if you are developing open source PHP software you should develop it in E_STRICT mode. This new E_DEPRECATED flag is actually part of E_ALL which sends a strong message that you shouldn&#8217;t be using these depreciated functions. I am a huge fan of anything that helps us write better code.</p>
<p>I hope everyone got through this post just fine. It is a long one. Leave comments (the comment section is OpenID enabled).</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/5-things-about-php-53-that-make-me-smile/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drop shadow tricks in Flex</title>
		<link>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/</link>
		<comments>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 15:20:11 +0000</pubDate>
		<dc:creator>Andrew Curioso</dc:creator>
				<category><![CDATA[Flex and AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://andrewcurioso.com/?p=53</guid>
		<description><![CDATA[Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve:

It seems easy enough so let&#8217;s give this a try:


&#60;mx:Style&#62;
HBox {
  paddingTop: 5;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Every display markup language has its frustrating moments. Adobe Flex isn&#8217;t any exception. I ran into a little trouble a while back when trying to put a drop shadow on a HBox component. Here is the effect that I wanted to achieve:</p>
<p><div id="attachment_57" class="wp-caption alignnone" style="width: 321px"><img class="size-full wp-image-57" title="Flex form with drop shadow header" src="http://andrewcurioso.com/wp-content/uploads/2009/05/picture-6.png" alt="Flex form with drop shadow header" width="311" height="216" /><p class="wp-caption-text">Flex form with drop shadow header</p></div><br />
<span id="more-53"></span></p>
<p>It seems easy enough so let&#8217;s give this a try:<br />
<span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<p>Usually the <em>dropShadowEnabled: true</em> would be enough but in this case you may be surprised if you put the above style into an MXML file with an HBox in it. Drop shadows don&#8217;t work on HBox components without some more tweaking. They don&#8217;t work for VBox, FormItem, Canvas, Grid, and Tile either. But dropShadowEnabled works beautifully to create Flex drop shadows on a component like TextInput.</p>
<p>What sets TextInput apart? It has a border by default. That is the key. Put <em>borderStyle: solid</em> in our style sheet then all the sudden our HBox has a drop shadow. Unfortunately it also has a nice one pixel border as well. To fix that we can set the borderThickness to zero and you&#8217;re done.</p>
<p><span class="syntaxhighlighterContainer">
<pre class="brush: xml;">
&lt;mx:Style&gt;
HBox {
  paddingTop: 5;
  paddingBottom: 5;
  paddingLeft: 5;
  paddingRight: 5;
  dropShadowEnabled: true;
  borderThickness: 0;
  borderStyle: solid;
}
&lt;/mx:Style&gt;
</pre>
<p></span></p>
<h3>Quick Two Point Summary</h3>
<ul>
<li>
<p>Drop shadows will be hidden if the component doesn&#8217;t have a border.</p>
</li>
<li>
<p>The border can be zero pixels.</p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://andrewcurioso.com/2009/06/drop-shadow-tricks-in-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
