<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>DevChix » PHP</title>
	
	<link>http://www.devchix.com</link>
	<description>Boys can't have all the fun</description>
	<pubDate>Sat, 04 Jul 2009 06:18:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/devchix/MWVA" type="application/rss+xml" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>From Python 2.6 to PHP 5.2: A circuitous journey</title>
		<link>http://www.devchix.com/2008/11/20/from-python-26-to-php-52-a-circuitous-journey/</link>
		<comments>http://www.devchix.com/2008/11/20/from-python-26-to-php-52-a-circuitous-journey/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 20:02:08 +0000</pubDate>
		<dc:creator>gloriajw</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[Introductions]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[People]]></category>

		<category><![CDATA[Python]]></category>

		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://www.devchix.com/?p=187</guid>
		<description><![CDATA[When I started heavily using PHP 5.2 (not by choice, I&#8217;ll admit), I was impressed, but I suffered from some incorrect assumptions about what PHP5 is and is not capable of doing. The good news is that it is more object oriented than it&#8217;s predecessor, but has some caveats to consider. Here are some things [...]]]></description>
			<content:encoded><![CDATA[<p>When I started heavily using PHP 5.2 (not by choice, I&#8217;ll admit), I was impressed, but I suffered from some incorrect assumptions about what PHP5 is and is not capable of doing. The good news is that it is more object oriented than it&#8217;s predecessor, but has some caveats to consider. Here are some things to be aware of when switching from a pure OO language to PHP5:</p>
<p>1: A nonexistent PHP array key generates no error or warning. When trying to iterate over a nonexistent array key, a warning occurs. In other languages, both of these conditions throw an exception.</p>
<p>Try this code for example:</p>
<pre>
&lt;?
$dictionary=array('one'=>'got one','two'=>'have two','four'=>'missing three?');
foreach (array_keys($dictionary) as $key)
{
	print "Key is:".$key.", value is:".$dictionary[$key]."\n";
}
print "Try undefined key three, no warning occurs:".$dictionary['three']."\n";
foreach ($dictionary['three'] as $value)
{
	print "Now we're iterating over a nonexistent key:";
	print "Key is: three, value is:".$dictionary['three']."\n";
}
?>
</pre>
<p>Running it results in this output:</p>
<pre>
php test.php
Key is:one, value is:got one
Key is:two, value is:have two
Key is:four, value is:missing three?
Try undefined key three, no warning occurs:

Warning: Invalid argument supplied for foreach() in /root/test.php on line 8
</pre>
<p>If it is vital to me to make sure I am aware of missing keys, I only have two choices. If I need a proactive solution, I have to use the array_key_exists() function to do existence checking before use. If I want a reactive solution, I  write a log scanner, to pick up on these warnings. In every other OO language I have used, an exception was thrown for this condition, and my exception handling determined if the error was vital enough to have to exit immediately or not. This seems like a more efficient way to handle this condition. I would imaging PHP5 does not do this because of it&#8217;s need to be backward compatible with PHP4, but this is a guess. </p>
<p>It would be wonderful to have a -OO flag for PHP, which gives you the option to run PHP and expect more standard, stricter OO behavior in these instances. </p>
<p>2: Warnings cannot be &#8220;caught&#8221; like exceptions. Exceptions and warnings are distinctly separate beasts, and never the twain shall meet. Fine, I thought, maybe I could detect warnings similar to how we detect errors. But it seems like warnings cannot be detected when they happen. There is no PHP code I know of which can check if a warning had occurred in runtime. I tried to detect it using array error_get_last() but to no avail. if you know how, post your trick here.</p>
<p>3: In PHP, &#8216;true&#8217; evaluates to an integer &#8216;1&#8242;. To get the boolean &#8216;true&#8217; value from a &#8216;true&#8217; statement, one needs to var_export() a true statement. Similarly, or maybe not, &#8216;false&#8217; evaluates to no output. Here is an example:</p>
<pre>
&lt;?
print "\nThe raw value of a true statement in PHP:".true;
print "\nThe raw value of a false statement in PHP:".false;
print "\nThe exported value of a true statement in PHP:".var_export(true,true);
print "\nThe exported value of a false statement in PHP:".var_export(false,true);
print "\n";
?>
</pre>
<p>And the output:</p>
<pre>
The raw value of a true statement in PHP:1
The raw value of a false statement in PHP:
The exported value of a true statement in PHP:true
The exported value of a false statement in PHP:false
</pre>
<p>This may not be noticeable to you in a standard expression. But if you&#8217;re doing funky stuff, like using the evaluated expression values as key references into the dictionary of a decision tree, for example, 1 does not equal &#8216;true&#8217;, and the difference matters quite a bit. </p>
<p>4: Long running processes with recursive circular references (such as Doctrine code) run out of memory. This is documented in many places, and the free() function works sometimes. A fix is coming in PHP 5.3. The foolproof solution for my code in production today (youch!) is to periodically restart the daemon. If you&#8217;re cringing right now, know that you&#8217;re not cringing alone. </p>
<p>There may be a part II to this article. Feel free to add your own PHP5 observations. </p>
<p>Gloria</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2008/11/20/from-python-26-to-php-52-a-circuitous-journey/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DevChix and PHPWomen form an affiliation!</title>
		<link>http://www.devchix.com/2008/02/05/devchix-and-phpwomen-form-an-affiliation/</link>
		<comments>http://www.devchix.com/2008/02/05/devchix-and-phpwomen-form-an-affiliation/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 21:54:48 +0000</pubDate>
		<dc:creator>desi</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://www.devchix.com/2008/02/05/devchix-and-phpwomen-form-an-affiliation/</guid>
		<description><![CDATA[A few weeks ago I was fortunate enough to meet Ligaya Turmelle one of the founders of PHPWomen and then last week we meet up for dinner. The conversation flowed so well that 4 hours passed in what seemed to be mere minutes. We had so much in common with how our organizations came about, [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago I was fortunate enough to meet Ligaya Turmelle one of the founders of <a href="http://phpwomen.org">PHPWomen</a> and then last week we meet up for dinner. The conversation flowed so well that 4 hours passed in what seemed to be mere minutes. We had so much in common with how our organizations came about, with all of the hopes and dreams we have for women in software development, and so much more. We decided that our goals were aligned so well that we should create an affiliation between our two organizations in hopes of creating a stronger support network for all women.  So I am very pleased to announce that we have formed an alliance. Hopefully this alliance will help both our organizations. We look forward to supporting, helping, and working our sisters over at <a href="http://phpwomen.org">PHPWomen</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2008/02/05/devchix-and-phpwomen-form-an-affiliation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Book Review: Pro Drupal Development</title>
		<link>http://www.devchix.com/2007/08/12/book-review-pro-drupal-development/</link>
		<comments>http://www.devchix.com/2007/08/12/book-review-pro-drupal-development/#comments</comments>
		<pubDate>Sun, 12 Aug 2007 20:28:30 +0000</pubDate>
		<dc:creator>Nola</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.devchix.com/2007/08/12/book-review-pro-drupal-development/</guid>
		<description><![CDATA[Book Site &#124; Sample Chapter: The Theme System &#124; Table of Contents
Many of you are aware of my current total infatuation with Ruby, and that I&#8217;ve used PHP for about 6 years and at one point decided I hated PHP&#8230;until, I needed it for a quick one-off page and then realized that PHP had its [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.apress.com/book/bookDisplay.html?bID=10258">Book Site</a> | <a href="http://www.apress.com/book/supplementDownload.html?bID=10258&amp;sID=4237">Sample Chapter: The Theme System</a> | <a href="http://www.apress.com/book/supplementDownload.html?bID=10258&amp;sID=4233">Table of Contents</a></p>
<p>Many of you are aware of my current total infatuation with Ruby, and that I&#8217;ve used PHP for about 6 years and at one point decided I hated PHP&#8230;until, I needed it for a quick one-off page and then realized that PHP had its place. Then again, <a href="http://www.rubygeek.com/2007/05/09/get-er-done/">I was totally frustrated with Ruby</a> when making my <a href="http://www.apieceacake.com">moms bakery site</a> and then turned to <a href="http://drupal.org/">Drupal</a> and <a href="http://gallery.menalto.com/gallery">Gallery</a> (another fine PHP project), which saved my bacon and I got a website and photo gallery up in a weekend. So, PHP and I have had our moments but I&#8217;m not abandoning it!<br/></p>
<p>Drupal powers some big sites, its not just for joe smoe&#8217;s blog. This is an interesting page about <a href="http://drupal.org/handbook/is-drupal-right-for-you">Is Drupal Right For You?</a> and if you are wondering if its something that would even work for you.</p>
<p>I was excited to get my hands on a review copy of Pro Drupal Development. Its no secret that coders hate documentation and Drupal has one of the most complete online documentation I&#8217;ve seen for an Open Source project, but its almost too hard to find what you need amongst so much. The Pro Drupal Book is a godsend for the drupal programmer, new and experienced alike. I wish it was written a year ago!</p>
<p>The book starts off with a quick overview of how Drupal is structured and defines terms such as hooks, node and blocks in just 10 pages. Chapter 2 is a A step-by-step tutorial with making a module. That is a great idea to start off quickly writing code. It get the reader involved and hands on. I really tire of books that have to start off with the history of the internet, html and how things have evolved. Get to the code dangit!! Kudos to the Authors for that! Chapter 3 gets into module specific settings, like how to get your module to show up on the admin page and storing user settings that your module needs.</p>
<p>After you&#8217;ve had some experience with the code then the book goes into details on the specific parts of Drupal:</p>
<ul>
<li>
    Menu System
  </li>
<li>
    Databases
  </li>
<li>
    Users
  </li>
<li>
    Nodes
  </li>
<li>
    Themes
  </li>
<li>
    Blocks
  </li>
<li>
    Form API
  </li>
<li>
    Filter System
  </li>
<li>
    Searching and Indexing
  </li>
<li>
    Files
  </li>
<li>
    Taxonomy
  </li>
<li>
    Caching
  </li>
<li>
    Sessions
  </li>
<li>
    JQuery
  </li>
<li>
    Localization
  </li>
<li>
    Using XML-RPC
  </li>
</ul>
<p>Drupal is a pretty amazing framework, when I read the code I say &#8220;why didn&#8217;t I think of that?&#8221; &#8230; the module and hook system is genius.</p>
<p>Then some more general topics:</p>
<ul>
<li>
    Writing Secure code
  </li>
<li>
    Development Best Practices
  </li>
<li>
    Optimizing Drupal
  </li>
<li>
    Installation Profiles
  </li>
</ul>
<p>One of the chapters I skipped ahead to read was The Form API. In my years of PHP I&#8217;ve often tried to come up with a framework for doing forms and I wanted to see how they did it. This chapter follows a tutorial style as well. The Form API allows you to define fields, their label, their value, description. Some frameworks take the template approach, where you hammer out your HTML. Some are more configuration based like Drupal making a multi-dim array with keys and values. I can see advantages to both. There is a hook function for validation which allows you to write your validation checks.</p>
<p>PHP gets a bad wrap for security, partly because its pretty easy to learn PHP and newbies don&#8217;t always realize what they are doing. There is a chapter devoted to security and includes even some things I didn&#8217;t know about &#8212; encoding mail headers. The Form API is very secure,&nbsp; one thing it does is check values that come from dropdowns were actually in the options and it wasn&#8217;t something that the hacker made up.</p>
<p>Developer Best Practices are great for the new developer, it talks about using cvs, tags, branches. It talks about how to create and apply patches (hint - you can contribute back to drupal). That is awesome. Alot of open source projects are like &#8220;HELP us, submit patches!&#8221; and the new user is left with uhhhhhh..how?</p>
<p>Caching is another interesting chapter. You will learn&nbsp; how caching works and how Drupal Core uses it. There is a Cache API that has methods for module creators to make their modules faster.</p>
<p>JQuery &#8230; I am not sure if I like it or not, but its part of Drupal 5! I skipped ahead to this chapter to see what its all about. There is a javascript hook built into Drupal making it easy to add, thats pretty cool.</p>
<p>One thing I found lacking in the book is anything about Testing. There are few pages on debugging and some modules to help with testing, but I would like to see more. At least some talk about selenium, which is great for a site made with any framework/cms.</p>
<p>Over all, Thanks APress for another great book!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2007/08/12/book-review-pro-drupal-development/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Getting started with YUI’s Connection Manager in Rails and PHP; or “All Happy Families Are Not Alike”</title>
		<link>http://www.devchix.com/2007/02/28/getting-started-with-yui%e2%80%99s-connection-manager-in-rails-and-php-or-all-happy-families-are-not-alike/</link>
		<comments>http://www.devchix.com/2007/02/28/getting-started-with-yui%e2%80%99s-connection-manager-in-rails-and-php-or-all-happy-families-are-not-alike/#comments</comments>
		<pubDate>Thu, 01 Mar 2007 03:38:42 +0000</pubDate>
		<dc:creator>sarah g</dc:creator>
		
		<category><![CDATA[Javascript/AJAX]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.devchix.com/2007/02/28/getting-started-with-yui%e2%80%99s-connection-manager-in-rails-and-php-or-all-happy-families-are-not-alike/</guid>
		<description><![CDATA[This post is geared towards folks who haven&#8217;t done the A part of AJAX before (And I mean the first A, as in Asychronous); are new to Yahoo&#8217;s implementation of the XMLHttpRequest object (The Yahoo! Connection Manager) and would like added information on how that works; or bothThis is not meant to supplant the excellent [...]]]></description>
			<content:encoded><![CDATA[<p>This post is geared towards folks who haven&#8217;t done the A part of AJAX before (And I mean the first A, as in Asychronous); are new to Yahoo&#8217;s implementation of the XMLHttpRequest object (The Yahoo! Connection Manager) and would like added information on how that works; or bothThis is not meant to supplant the <a target="_blank" href="http://developer.yahoo.com/yui/connection/">excellent yui! tutorials</a> which you should read in detail for thorough explanations and examples. What I am adding here are a few examples of using this in the Rails framework and some thoughts on the callback object and scope.</p>
<p>Your &#8220;AJAX&#8221; goals are simple: you want to communicate with your server, get a response back that you can use (or not), do something with that response (or not), and move on. As this is <strong>asynchronous</strong>, you want to do this without reloading your web page. Or, as a client once said to me, referring to certain animated gifs in the upper right-hand corner of certain browsers, without &#8220;making the world spin&#8221;. To this end, Yahoo! has supplied us one line of code:</p>
<pre>var transaction =
YAHOO.util.Connect.asyncRequest(
method, uri, callback, postData);</pre>
<p>or, same line with some data plugged in:</p>
<pre>var transaction =
YAHOO.util.Connect.asyncRequest(
'POST',   'php/post.php', callback,"id=1&#038;old_id=2");</pre>
<p>When I was making the switch from synchronous to a-, it helped me to visualize a standard web form to see how form elements and attributes are translated to an AJAX request. It&#8217;s pretty obvious, but if you need an &#8220;aha!&#8221; moment, the above line is akin to the html form printed below (though unless you&#8217;re one of those people whose definition of interactivity is &#8220;The Monologue&#8221;, do refrain from creating forms with 2 hard-coded hidden inputs and nothing else! :)).</p>
<pre>&lt;form method="post" action="php/post.php"&gt;
&lt;input type="hidden" name="id" value="1" /&gt;
&lt;input type="hidden" name="old_id" value="2" /&gt;
&lt;input type="submit"&gt;
&lt;/form&gt;</pre>
<p>So, excluding a reference to the <strong>callback </strong>for the moment (which is not addressed in this example), that form maps to the Connection Manager call quite simply: method, action (uri), data.  Let&#8217;s look at the arguments required:</p>
<p><strong>method</strong>: the method of the server request (<strong>POST, GET </strong>and others also available).</p>
<p><strong>uri: </strong>  the uri that&#8217;s receiving and processing the data you send (in our example, &#8220;php/post.php&#8221;). YUI&#8217;s examples use php, but, if you&#8217;re using the Connection Manager in a Rails app, it&#8217;s easy to adapt: your argument <strong>uri </strong>might read “/projects/update which would pass the data to the <strong>update method </strong>in <strong>projects_controller.rb</strong>, which would then be able to access the  data through the <strong>params </strong>array, like so:</p>
<pre>def update
@project = Project.find(params[:id])
end</pre>
<p>In php you&#8217;d probably do some type of db query [assume input cleanup and some type of database abstraction layer, such as <a target="_blank" href="http://pear.php.net/package/DB_DataObject/">PEAR/DB_DataObject</a>,  here]</p>
<pre>$project = DB_DataObject::factory('Projects');
$project->get($_POST['id']);</pre>
<p><strong>Callback</strong>: a reference to the callback object you are supplying. This is how everything is handled.  More on that in a minute.</p>
<p><strong>postData</strong>:  the data itself in standard query-string format (&#8221;new=1&#038;old=2&#8243;). NOTE: if you&#8217;re doing a GET transaction, your 4th argument would be <strong>false</strong> and your second argument would include the url and query string, like so:</p>
<pre>“php/post.php?new=1&#038;old=2".</pre>
<p><strong>So, what&#8217;s this </strong><strong>callback</strong>?. In a synchronous transaction, you have the luxury of redrawing the page to process your data (and yes, nothing says luxury like a nice, slow, page reload&#8230;). In an asynchronous transaction you need to essentially &#8220;sneak&#8221; your data back into the page without reloading it. This is where your callback object comes in. It helps you get your data &#8220;in the door&#8221;, so to speak, so your page or application can change in a way that feels seamless to the user but often returns a visible result (changing a div, displaying some text, etc.) and if not a visible result at least a meaningful one (setting the value of a hidden form element, for example). Your callback is responsible for executing actions based on the data retrieved (or the failure to retrieve data) from the uri.  In a standard synchronous form this action might be &#8220;generate an HTML table that displays your database results&#8221;. Or, &#8220;Print a message saying there are no results&#8221;. Of course, you can do anything  you want with your data, that&#8217;s just an example of a fairly common scenario.</p>
<p>Once you&#8217;ve sent  your data to the uri for processing, you need to wait for your response &#8212; without, of course, appearing to wait (save for the ubiquitous web 2.0 spinner you know you&#8217;re dying to try!).  And, of course you want to know if your transaction failed. If you don&#8217;t watch for these things &#8212; “success&#8221; and “failure&#8221; in technical terms &#8212; you&#8217;re not going to be able to make an appropriate decision about what to do next in your app.  So you feed your AJAX request a callback object:  an object that defines functions for what to do in the cases of success and failure. In simplest terms, we&#8217;ve got</p>
<pre>var callback = {
success: handleSuccess,
failure: handleFailure
};</pre>
<p>where “handleSuccess&#8221; and “handleFailure&#8221; are user-defined functions that take the http response object and do stuff with it.</p>
<pre>handleSuccess = function(o){
// cheer! (or process data returned from the server)
}

handleFailure = function(o){
// cry, vow to try again! (or display failure message)
}</pre>
<p>There&#8217;s also the ability to pass <a target="_blank" href="http://developer.yahoo.com/yui/connection/#scope">scope</a>, <a target="_blank" href="http://developer.yahoo.com/yui/connection/#timeout">timeouts, and additional arguments</a> to the callback object. To do so you&#8217;d read the great tutorials at the links above and add the lines below, of course changing the values to values meaningful in your application.</p>
<pre>scope: Ajaxobject,
timeout: 5000,
args: ['arg1', 'arg2']</pre>
<p><strong>The handlers</strong>. handleSuccess and handleFailure both take an object <strong>o</strong>, which is the http response object. There&#8217;s a detailed list of all the <a target="_blank" href="http://developer.yahoo.com/yui/connection/#success">properties of <strong>o</strong></a> on the yui page (Not to be confused with the <em>Story of O</em>, which I will not link to as it is beyond the scope of this article, you dirty rascals, you&#8230;).  The property you&#8217;ll likely use most often is <strong>o.responseText</strong>, which is the server&#8217;s response as a string.  This is what you pass back from good old &#8216;php/post.php&#8217;, and getting it is simple: echo. What? echo. What? echo..o..o&#8230; ok, sorry, moving on. For instance, if we wanted to capture the update_date in our successHandler to print to  our page and we&#8217;re using php, we&#8217;d write something like this:</p>
<pre>echo $project->update_date;</pre>
<p>and if we&#8217;re in Rails? something like this:</p>
<pre>render_text @project.update_date</pre>
<p>If you need more data than a string &#8212; an array or collection of objects  passed back from the server, you&#8217;ll find that&#8217;s simple, too: call the ruby method <strong>to_json()</strong> on your array instead. This essentially serializes your object so it can survive the journey to the Client. Once there, you can access the data using JavaScript&#8217;s magic wand: eval().  It&#8217;s great.  So if you had an array of users connected to a project (and your database relationships are set up correctly), you could write</p>
<pre>render_text @project.users.to_json</pre>
<p>in php, assume you&#8217;ve got your $users array, and use print_r</p>
<pre>print_r($users);</pre>
<p>The in your JavaScript successHandler use eval(), like so:</p>
<pre>var users =  eval(o.responseText)</pre>
<p>and bingo: in two lines you&#8217;re happily in your JavaScript parsing your users array like you would any other JavaScript array. You have connected your server to your DOM and no one is the wiser for it.</p>
<p>All this is great.  We have our AJAX call and our callback object and are ready to go.  But, suppose you don&#8217;t want to rewrite the AJAX call all over your app?  The Yahoo folks have a great example of a &#8216;“hypothetical ajax object&#8221; (mysteriously named &#8220;AjaxObject&#8221;)  that encapsulates success, failure, and process methods and calls a callback object that defines AjaxObject as it&#8217;s scope. Encapsulating your AJAX request so you can call it from wherever you want in your scripts in a DRY fashion makes your code cleaner and easier to manage. Yahoo! does this well in their example: in my usage I changed it up a little bit to meet my needs.</p>
<p>To quote the great Chicago writer Leo Tolstoy from his famous novel <em>Anna Karenina Does Lake Michigan</em>, &#8216;“Happy families are all alike; every unhappy family is unhappy in its own way&#8221;.     I&#8217;ve learned that when working on an app, the opposite is true: success cases call for a range of actions: failures can more easily handled (log, display error, abort).  Based on this, I&#8217;ve adapted the yui AjaxObject example to accept a postAction, successHandler, and object (used to define scope). This allows you to call AjaxObject from other objects, pass specific success handlers, and pass <strong>this </strong>(a reference to your current object) so you can access it in your successHandler from within the calling object. The AjaxObject builds the callback using those arguments.  Like so:</p>
<pre>var AjaxObject = {

handleFailure:function(o){
// Fail gracefully
},

/**
* Wrapper for AJAX calls using YUI connector
*
* @param postAction {String} URL to post to
* @param callBackSuccess {String} Success handler
* @param postData {String} Data to post
* @param obj {Object} Object that handler has scope in
*
*/
startRequest:function(postAction, callBackSuccess, postData, obj) {

var callback = {
success:callBackSuccess,
failure:this.handleFailure,
scope:obj
}
// ASSUME you've shortened your yui connection mgr to $C
$C('POST', postAction, callback, postData);
}

};</pre>
<p>Then you can call AjaxObject from within a class, like so, and pass it a class method as it&#8217;s success-handler:</p>
<pre>var Project = function Project(){
// initialize project however you like
this.foo = "bar";
...
// CREATE in db and return id
AjaxObject.startRequest('/project/create',
this._generateDbId, postData, this);

}   // Success handler  Project.prototype._generateDbId = function(o){
if(o.responseText !== undefined){
this._setDbid(Number(o.responseText));
// DO other stuff..
}
}</pre>
<p>This way your AJAX calls are in one place, you can use them in the scope of the calling object and define as many success handlers as success cases (or pass false); and fail in one standard way (gracefully, of course). Of course, this can be adapted to pass failure cases in too, or however you like. This was a way I found helpful in my work, and I hope it&#8217;s helpful to you as well.  And thanks again to the folks at Yahoo! for providing so much great stuff to work with in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2007/02/28/getting-started-with-yui%e2%80%99s-connection-manager-in-rails-and-php-or-all-happy-families-are-not-alike/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Book Review: Pro PHP Security</title>
		<link>http://www.devchix.com/2007/02/25/book-review-pro-php-security/</link>
		<comments>http://www.devchix.com/2007/02/25/book-review-pro-php-security/#comments</comments>
		<pubDate>Mon, 26 Feb 2007 04:27:14 +0000</pubDate>
		<dc:creator>Nola</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Reviews]]></category>

		<category><![CDATA[Servers]]></category>

		<guid isPermaLink="false">http://www.devchix.com/2007/02/25/book-review-pro-php-security/</guid>
		<description><![CDATA[ProPHP Security
Published by: Apress
Authors: Chris Snyder and Michael Southwell
Book Site &#124; Sample Chapter: Preventing SQL Injection &#124; Table of Contents
At first, I thought this book was all about cleaning your input variables and filtering your output, XSS attacks, SQL injections but I was most presently surprised to find that it was that and so much [...]]]></description>
			<content:encoded><![CDATA[<h2>ProPHP Security</h2>
<p>Published by: Apress</p>
<p>Authors: Chris Snyder and Michael Southwell</p>
<p><a target="_blank" href="http://apress.com/book/bookDisplay.html?bID=437">Book Site</a> | <a target="_blank" href="http://apress.com/book/supplementDownload.html?bID=437&#038;sID=2957">Sample Chapter: Preventing SQL Injection</a> | <a target="_blank" href="http://apress.com/book/supplementDownload.html?bID=437&#038;sID=2955">Table of Contents</a></p>
<p>At first, I thought this book was all about cleaning your input variables and filtering your output, XSS attacks, SQL injections but I was most presently surprised to find that it was that and so much more! In fact, I would have called this &#8220;ProPHP Security and Administration&#8221; instead! It is absolutely fantastic. It really is about security in all of the facets of web development - from server, to code, to database to the system users.</p>
<p>The book is divided into 4 parts:</p>
<ul>
<li>Part 1: The Importance of Security</li>
<li>Part 2: Maintaining a Secure Environment</li>
<li>Part 3: Practicing Secure PHP Programming</li>
<li>Part 4: Practicing Secure Operations</li>
</ul>
<p>Here are some brief overviews of the sections and the tidbits I found interesting:</p>
<p><strong>Part 1:</strong></p>
<p>The first part is the shortest and gives a general overview the what and why of security.</p>
<p><strong>Part 2:</strong></p>
<p>The second is much more hearty and goes into detail about Shared hosts and why they are secure and how to make the more so. It even dips into alternatives for the traditional shared hosts and goes into Virtual Machines. This is valuable to not only to administrators but to PHP Developers. After reading this, I understand the &#8220;why&#8221; behind many of the things about shared hosting that I found frustrating.</p>
<p>One of the most important things I found in this chapter is how to maintain separate development and production environments. When I was helping to set this up at one of my past jobs it was a topic that I couldn&#8217;t find much information about. It also makes mention of version control, using wikis, bug tracking, sandbox and testing! Oh and here&#8217;s a conceptÃ¢â‚¬Â¦. pretend your live system failed &#8212; how well does your backup plan work?</p>
<p>How many times have I thought, I should make a cron job to back up my database to my home server every day/week? Have I ever done this? No! But now I have no excuse! Backing up a database and storing remotely is one of the sections in this chapter and code included! Fantastic.</p>
<p>There are chapters about Encryption theory and practice which I read several times to understand. It was interesting but it wasn&#8217;t something I have to do right now in my life, but I will return to this book to refresh my memory when I do.</p>
<p>Securing Network connections SSL and SSH, these proved helpful as I have become the &#8220;Reluctant System Admin&#8221; for one of my projects &#8212; partly because if they were to hire a part time person I&#8217;d rather they get a CSS person and I&#8217;d rather do the sys admin!</p>
<p>The Controlling Access section goes into details about using certificates with php, single sign-on, basic and digest http authentication Ã¢â‚¬Â¦ whoa this is some deep stuff! But good, when I was looking into this for a project a few years ago I couldn&#8217;t find anything helpful. It continues with then permissions and restrictions, a lot about Unix permissions and keeping things running where they should, securing databases and PHP Safe mode!</p>
<p><strong>Part 3</strong></p>
<p>Finally &#8212; the stuff that I thought the book would be about - validating user input, filtering output, preventing cross site scripting attempts, remote execution.. so much more to security than I thought! It talks about securing temp files, I always assumed the OS handled this and I didn&#8217;t need to worry.</p>
<p><strong>Part 4</strong></p>
<p>Ahh &#8212; Practicing Secure OperationsÃ¢â‚¬Â¦ all you ever wanted to know about making sure your users are humans, verifying your users, setting roles for users, logging your users actions, preventing data loss, executing system commands safely, working with webservices and finally Peer Reviews! Sometimes it&#8217;s that extra pair of eyes that can see things you miss.</p>
<p>Something I find interesting - in the section about preventing data loss, it talks about setting a flag on records that are &#8220;deleted&#8221; and then making a db view of the &#8220;good&#8221; data  and using that to select from. One of the things I like in Ruby On Rails is this &#8220;acts_as_paranoid&#8221; model option that does about the same thing. Neato.</p>
<p>Pro PHP Security is a most excellent read and so much deeper than my brief overview here. It will be a handy book on my shelf to keep me on my toes regarding security in all areas of web development, from the server to the code, to the users, to best practices of security you will find this is a helpful book too!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2007/02/25/book-review-pro-php-security/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Book Review: Beginning Ajax with PHP by Lee Babin</title>
		<link>http://www.devchix.com/2006/12/13/book-review-beginning-ajax-with-php-by-lee-babin/</link>
		<comments>http://www.devchix.com/2006/12/13/book-review-beginning-ajax-with-php-by-lee-babin/#comments</comments>
		<pubDate>Wed, 13 Dec 2006 14:26:54 +0000</pubDate>
		<dc:creator>Nola</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[Javascript/AJAX]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.devchix.com/?p=18</guid>
		<description><![CDATA[Book Review
Beginning Ajax with PHP by Lee Babin, published by Apress
Book Site &#124; Sample Chapter: 3 PHP and Ajax &#124; Table of Contents
Although no stranger to Ajax, I received a review copy of Beginning Ajax with PHP expecting some watered down presentation of Javascript with some PHP thrown in. I was quite surprised to find [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal">Book Review<br />
Beginning Ajax with PHP by Lee Babin, published by Apress</p>
<p class="MsoNormal"><a href="http://apress.com/book/bookDisplay.html?bID=10117">Book Site</a> | <a href="http://apress.com/book/supplementDownload.html?bID=10117&#038;sID=3896">Sample Chapter: 3 </a><a href="http://apress.com/book/supplementDownload.html?bID=10117&#038;sID=3896">PHP and Ajax</a> | <a href="http://apress.com/book/supplementDownload.html?bID=10117&#038;sID=3897">Table of Contents</a></p>
<p class="MsoNormal">Although no stranger to Ajax, I received a review copy of <em>Beginning Ajax with PHP</em> expecting some watered down presentation of Javascript with some PHP thrown in. I was quite surprised to find a good presentation of using Ajax and PHP, easy enough for the beginner and still interesting for those who have done it for years.</p>
<p class="MsoNormal">
<p class="MsoNormal">The book starts out exactly how I would write it &#8212; SIMPLE! The first time I did Ajax with XHR (xml http request), I used a plain text file, which I then read into a DIV at the click of a link. This takes a similar approach and has data stored in an array which is then accessed with a simple call to a PHP file. The following chapter, takes it a step further and this building upon previous chapters is a common theme in the book.</p>
<p class="MsoNormal">
<p class="MsoNormal">After going through the basics, the book gets into more practical uses of Ajax. The latter chapters talk about using forms to pass along data to be processed by Ajax and doing form validation. It also gives a good explanation of the proper use of the form methods GET and POST. It goes into detail about uploading images and other files using a hidden form submit trick, since XHR doesn&#8217;t support file uploading (javascript is not allowed to access files on your harddrive). And this chapter is the perfect predecessor to the &#8220;Real-World Ajax Application&#8221; chapter where you will take what you have learned and create an Ajax based photo gallery. Practical, hand-on is the best way to learn something IMHO (Sorry &#8220;Hello World&#8221; scripts!). It is interesting that this chapter is in the middle of the book, when I would expect it at the end. Perhaps the author wanted the user to jump in and try it, instead of persevering to the end. I don&#8217;t know about you, but often the last few chapters of the book go unread by me.</p>
<p class="MsoNormal">
<p class="MsoNormal">After the reader has confidence on how to use AJAX, the book gives the warning, Ã¢â‚¬Å“Whoa! Wait a minute! AJAX isn&#8217;t appropriate for EVERYTHING!Ã¢â‚¬Â It gives examples of when AJAX would be a good idea and when it would not. I think this is pretty important as each CEO now wants Ajax everywhere in their application but it&#8217;s not always the best solution! And it talks about the classic, Ã¢â‚¬Å“THE BACK BUTTONÃ¢â‚¬Â, problem. Then, in the same chapter, the book takes sort of a funny turn (in my opinion) and gives an introduction to PEAR.  The book explains how to use PEAR&#8217;s HTML_TABLE class to illustrate a good use for Ajax in creating an Excel-like grid that sums columns. This is a very cool class but would have been better suited for an appendix.</p>
<p class="MsoNormal">
<p class="MsoNormal">The rest of the book seems to be a random splattering of interesting topics: web services, map applications, cross-browser issues (touches again on the back button problem - but a solution this time!). There is also a brief mention of security. This should have been more in the middle of the book (see above for skipped last chapters syndrome). What then follows is a testing and debugging chapter which would have been more effective as the 3 or 4th chapter in the book. Finally there is a chapter about the browser DOM.</p>
<p class="MsoNormal">
<p class="MsoNormal">A great minor addition to the book would be an overview of some Ajax libraries such as Prototype, JQuery, Dojo, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2006/12/13/book-review-beginning-ajax-with-php-by-lee-babin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Book Review: PHP Hacks</title>
		<link>http://www.devchix.com/2006/11/10/book-review-php-hacks/</link>
		<comments>http://www.devchix.com/2006/11/10/book-review-php-hacks/#comments</comments>
		<pubDate>Fri, 10 Nov 2006 14:15:56 +0000</pubDate>
		<dc:creator>Nola</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://www.devchix.com/?p=15</guid>
		<description><![CDATA[Book Review: PHP Hacks by Jack D. Herrington, published by O&#8217;Reilly
I had borrowed a Perl Hacks book from and friend and really liked it, it was great! It had a lot of practical things as well as some fun things. I expected the same from PHP Hacks and I was not disappointed!
HereÃ¢â‚¬â„¢s the table of [...]]]></description>
			<content:encoded><![CDATA[<p>Book Review: PHP Hacks by Jack D. Herrington, published by O&#8217;Reilly</p>
<p>I had borrowed a Perl Hacks book from and friend and really liked it, it was great! It had a lot of practical things as well as some fun things. I expected the same from PHP Hacks and I was not disappointed!</p>
<p>HereÃ¢â‚¬â„¢s the table of contents:<br />
<a href="http://www.oreilly.com/catalog/phphks/toc.html">http://www.oreilly.com/catalog/phphks/toc.html </a></p>
<p>OÃ¢â‚¬â„¢Reilly also has some sample hacks:<br />
<a href="http://www.oreilly.com/catalog/phphks/chapter/index.html">http://www.oreilly.com/catalog/phphks/chapter/index.html</a></p>
<p>Here&#8217;s some that I found interesting:</p>
<p><span style="font-weight: bold">The Practical Stuff</span><br />
Breadcrumbs<br />
Not familiar with the term? <a href="http://en.wikipedia.org/wiki/Breadcrumb_%28navigation%29">Check it out</a>. I think this hack may get you started on a breadcrumb function/method. In the end they suggest a xml file to show which page urls were parents of which. The way I&#8217;ve done this before was I had a class for each major section, and sub section, and had a method  ->addCrumb($label, $url) which I had in the constructorÃ¢â‚¬Â¦and the subsections of course would call the parent contructor and it kept the breadcrumb hierarchy intact. But hey, thatÃ¢â‚¬â„¢s the fun of programming - different ways to do the same thing to meet different needs! Definitely a good hack to get the juices flowing!</p>
<p>Building Lightweight HTML Graphs<br />
Don&#8217;t want to use flash to display a graph? use PHP to figure out the ratios and give you a width and use a table. I&#8217;ve done something similar by figuring out the width of a div, making the background a colorÃ¢â‚¬Â¦ and I have used 1&#215;1 pixel images that have been stretched to a certain width and height. ItÃ¢â‚¬â„¢s a very lightweight download for your user, thatÃ¢â‚¬â„¢s for sure! Later in the book, there&#8217;s a hack for creating a Dynamic HTML Graph that will change without reloading the page.</p>
<p>Put an Interactive Spreadsheet on your Page<br />
This one is so cool &#8212; you need to read about it in the book yourself! Lets says, move over Google Spreadsheets! We can do it too!</p>
<p>Create Link Graphs<br />
I call these Tag Clouds, not sure why they call them Link Graphs here in the book &#8212; probably, tag clouds has been copy written by some Web 2.0 smartass. Here I am, sue me! This is a unique and visual way to show the popularity of certain words in a group. Rather than a numbered list, this is visual. I had this discussion not too long ago with a group and sadly, most of them didn&#8217;t get it. I think if I actually used this sort of technique on a page, I&#8217;d include a &#8220;What&#8217;s this?&#8221; link or an alternative view.</p>
<p>Create Dynamic Database Objects<br />
This was very interesting to me because I love Active Record in Rails. This relies on some of the magic of PHP5 to work, probably this is not going to be the best performance code but really &#8212; is anything easy the fastest?</p>
<p>Generating CRUD Database Code<br />
Similar to previous, but a create-once and go method, this hack will read from a xml file and create CRUD objects for maintaining your database. These will probably be faster then the previous one -but you&#8217;d have to run this script or update manually when your schema updates. Some people hate code generation - some don&#8217;t. Pear&#8217;s DB_DataObject is a similar concept.</p>
<p>There are a few other nifty database hacks making this my favorite section of the book!</p>
<p>Turn any Object into an Array<br />
Using foreach is my default iteration function and using the PHP 5 iteration interface on any object to give it that functionality is awesome. This is one of the most practical design patterns (other than the other favorite: singleton) that I talk about to people who ask me - what are design patterns and why should I care? Speaking of design patterns - tired of reading a design pattern book and trying to figure out the smalltalk or java code? the design pattern section of the book has diagrams and sample code that you can understand.</p>
<p><span style="font-weight: bold">Fun Stuff</span></p>
<p>Build a DHTML Binary Clock<br />
What is that you say? Take a look at <a href="http://www.thinkgeek.com/homeoffice/lights/59e0/">ThinkGeek</a> and learn how to make something similar in DHTML. Yes, this is not practical but its fun. Something fun is always a great way to get excited about programming and enjoy yourself.</p>
<p>Generate Your Unit Tests<br />
I put this in the fun section because testing IS fun - I love it. One of the things people (normal people, not wacky test freaks like me) complain about testing is - no time! Here&#8217;s a hack that will let you put your test in a comment and running this script on it will pull out those comments and write your test for you. Nifty!</p>
<p>Build GUI Interfaces with GTK<br />
I&#8217;ve always wanted to try something with GTK, but never have. This hack shows you how to build a regex expression tool to test and play around with regex. I&#8217;ve had programs like this and they are darn handy when you want to do a quick check. So, after you&#8217;ve had your fun building this &#8212; its practical as well.</p>
<p>Send RSS feeds to your IM Application using Jabber<br />
Depending on your use, this may in fact be practical but I think its rather fun. I have not figured out a use for this myself but the book uses it to send weather forecasts to your IM client. Neat-o<br />
<br style="font-weight: bold" /><span style="font-weight: bold">What I didn&#8217;t like about this book</span><br />
not too much in the way of checking input variables. I know, probably they &#8220;leave that as exercise to the reader&#8221; but noobs and experts alike need to get this ingrained into the head by default. So I suggest also picking up <a href="http://www.oreilly.com/catalog/phpsec/index.html">Essential PHP Security</a></p>
<p><span style="font-weight: bold">What I like </span><br />
ER diagrams and control flow - Nice!<br />
Handy size</p>
<p>I&#8217;ve only touched on a few of the great hacks and there are many more I also like, but didn&#8217;t really want to give away the entire book! I suggest you pick it up and keep it handy. Next time you are bored &#8212; flip though and find something interesting!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devchix.com/2006/11/10/book-review-php-hacks/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
