<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 19 Jun 2013 17:34:54 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Bob Majdak: On SQL in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19593</guid>
      <link>http://www.phpdeveloper.org/news/19593</link>
      <description><![CDATA[<p>
In a new post to his site <i>Bob Majdak</i> looks at <a href="http://catch404.net/2013/05/on-sql-in-php/">using SQL in PHP</a> and some of the challenges he's come across (some of them with his own tools). He talks about things line inline SQL, loading SQL by unique key or creating a "build object".
</p>
<blockquote>
There is no right or wrong way, but no matter what there is no *pretty* way to do SQL inside of a PHP application. I have been having a personal debate with myself all week about how to make SQL statements nicer in an application without going to a huge DBAL package like Doctrine.
</blockquote>
<p>
He looks at each idea and provides some of the pros and cons about each of them, noting that he hasn't quite decided on which is the best method. Some sample code is included to help clarify the points, showing the "find by unique key" version and how a more complex query might be created with the "builder object."
</p>
Link: http://catch404.net/2013/05/on-sql-in-php]]></description>
      <pubDate>Thu, 16 May 2013 10:11:29 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Josh Adell: Serializing Data Like a PHP Session]]></title>
      <guid>http://www.phpdeveloper.org/news/19534</guid>
      <link>http://www.phpdeveloper.org/news/19534</link>
      <description><![CDATA[<p>
In <a href="http://blog.everymansoftware.com/2013/05/serializing-data-like-php-session.html">this new post</a> <i>Josh Adell</i> looks at working with PHP sessions and how you can manually encode data to look as if it came from the normal session handling.
</p>
<blockquote>
If you have ever popped open a PHP session file, or stored session data in a database, you may have noticed that this serialization looks very similar to the serialize function's output, but it is not the same. Recently, I needed to serialize data so that it looked like PHP session data (don't ask why; I highly suggest not doing this if it can be avoided.) It turns out, PHP has a function that encodes data in this format: <a href="http://php.net/session_encode">session_encode</a>. 
</blockquote>
<p>
Unfortunately, this method doesn't take arguments - it just outputs the encoded version of the current session data. So, he came up with his own encode/decode methods that use the PHP session, extract the serialized string and return it.
</p>
Link: http://blog.everymansoftware.com/2013/05/serializing-data-like-php-session.html]]></description>
      <pubDate>Thu, 02 May 2013 09:11:33 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Parsing XML With SimpleXML]]></title>
      <guid>http://www.phpdeveloper.org/news/19171</guid>
      <link>http://www.phpdeveloper.org/news/19171</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial <a href="http://phpmaster.com/parsing-xml-with-simplexml/">introducing you to SimpleXML</a>, a handy bit of functionality included with the base PHP install to make working with XML (well, reading it) much simpler.
</p>
<blockquote>
Parsing XML essentially means navigating through an XML document and returning the relevant data. An increasing number of web services return data in JSON format, but a large number still return XML, so you need to master parsing XML if you really want to consume the full breadth of APIs available. Using PHP's SimpleXML extension that was introduced back in PHP 5.0, working with XML is very easy to do. In this article I'll show you how.
</blockquote>
<p>
He starts with some basic usage of the SimpleXML parsing, giving an example XML to parse, the resulting object and how to access the data inside it. There's also a bit about dealing with namespaces in the XML you're parsing and a more practical example - parsing the output of a YouTube feed to get links to various videos.
</p>]]></description>
      <pubDate>Tue, 12 Feb 2013 12:48:34 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Sherif Ramadan: How to Write an Operator Precedence Parser in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/19068</guid>
      <link>http://www.phpdeveloper.org/news/19068</link>
      <description><![CDATA[<p>
<i>Sherif Ramadan</i> has a post looking at <a href="https://sheriframadan.com/2013/01/how-to-write-an-operator-precedence-parser-in-php/">creating a better operator precedence parser</a> in PHP. <a href="https://github.com/srgoogleguy/Mphp/">His example</a> is a fully PHP implementation that takes equation strings and evaluates them to create the result.
</p>
<blockquote>
Operator precedence parsers are very simple on the surface. So don't feel in the least bit intimidated, because by the time you've read through this I hope to have you walk away with a solid foundation on how to write your very own operator precedence parser. The goal is to understand how to solve the problem of operator precedence parsing, and not necessarily to write your own parser. Learning how the problem can be solved is the most important thing to take away from this article.
</blockquote>
<p>
He starts with an introduction to the concepts behind "operator precedence" including processing order and grouping. He also mentions infix and postfix (RPN) notations for handling different formats of equations. He used the "Shunting-yard Algorithm" and how it relates to handling the different parts of the equation, one at a time, in the correct order. He rest of the post is dedicated to the details of the execution in the tool, including code examples and the tokenization of the strings passed into it.
</p>]]></description>
      <pubDate>Mon, 21 Jan 2013 11:21:22 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Mike Purcell's Blog: PHPUnit - Upgrade - Convert assertType to assertInternalType]]></title>
      <guid>http://www.phpdeveloper.org/news/17982</guid>
      <link>http://www.phpdeveloper.org/news/17982</link>
      <description><![CDATA[<p>
In <a href="http://melikedev.com/2012/05/18/phpunit-upgrade-convert-asserttype-to-assertinternaltype/">this quick post</a> to his blog, <i>Mike Purcell</i> mentions the deprecation of the "assertType" assertion and includes some code you can add to correct the issue in your tests.
</p>
<blockquote>
We recently upgraded phpunit from a very old version to the current 3.6.x version (at time of writing). During the upgrade I noticed that assertType is no longer supported in many of our tests which were testing if something was a string, an array, or an object. So I had to write a quick script to update assertType to assertInternalType and figured I would post it for others if they needed to do the same.
</blockquote>
<p>
The code goes into each of your tests (recursively) and finds the places where the "assertType" assertion is used and replaces it with its newer cousin "assertIntrnalType". 
</p>]]></description>
      <pubDate>Mon, 21 May 2012 09:56:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Bulletproofing Database Interactions with PHPUnit's Database Extension]]></title>
      <guid>http://www.phpdeveloper.org/news/17794</guid>
      <link>http://www.phpdeveloper.org/news/17794</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial showing you how to <a href="http://phpmaster.com/bulletproofing-database-interactions">test your application's interface with the database</a> using "bulletproof" PHPUnit testing.
</p>
<blockquote>
There's already a great article here that discusses Test Driven Development, but did you know that you can also test the code that interacts with your database? Especially if your application is data intensive, subjecting your CRUD code to a battery of tests is good practice that helps ensure that your application is working correctly. In this article you will be learning how to write database tests in PHP using PHPUnit and its database extension. 
</blockquote>
<p>
Included in the post is an <a href="https://github.com/phpmasterdotcom/BulletproofingDatabaseInteractions/blob/master/schema.sql">example schema</a> and an example of the seed data (defined as XML) for the testing to use as predictable data in its execution. His test class extends <i> PHPUnit_Extensions_Database_TestCase</i> (instead of the usual <i>PHPUnit_Framework_TestCase</i>) and a test for a basic "getArticles" method in his "IArticleDAO" class. By calling the "createXMLDataSet" method, the test loads in the pre-defined XML records and allows the correct evaluation of the assertions,
</p>]]></description>
      <pubDate>Tue, 10 Apr 2012 08:50:10 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Joseph Scott's Blog: Why PHP Strings Equal Zero]]></title>
      <guid>http://www.phpdeveloper.org/news/17679</guid>
      <link>http://www.phpdeveloper.org/news/17679</link>
      <description><![CDATA[<p>
<i>Joseph Scott</i> has a new post to his blog looking at "<a href="http://josephscott.org/archives/2012/03/why-php-strings-equal-zero/">why PHP strings equal zero</a>" - that when you use the "==" operator on a string to compare to zero, it's true.
</p>
<blockquote>
The issue of PHP strings equaling zero has come up a few times recently. [...] Running that will display Equals zero!, which at first glance probably doesn't make much sense. So what is going on here?
</blockquote>
<p>
He gets into the specifics of what's happening - a bit of type jugging, less strict comparison since it's the "==" versus "===" and how the <a href="http://php.net/manual/en/language.types.string.php">PHP manual</a> talks about strings being converted to numbers. 
</p>
<blockquote>
While I still think it is odd that the string gets cast as an integer instead of the other way around, I don't think this is a big deal. I can't recall a single time where I've ever run into this issue in a PHP app. I've only seen it come up in contrived examples like the ones above.
</blockquote>]]></description>
      <pubDate>Thu, 15 Mar 2012 09:47:49 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso's Blog: How to use eval() without using eval() in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/17665</guid>
      <link>http://www.phpdeveloper.org/news/17665</link>
      <description><![CDATA[<p>
In <a href="http://gonzalo123.wordpress.com/2012/03/12/how-to-use-eval-without-using-eval-in-php/">this new post</a> <i>Gonzalo Ayuso</i> talks about "using eval without using eval" in PHP applications - executing PHP code without having to use the <a href="http://php.net/eval">eval</a> function to do it.
</p>
<blockquote>
Yes I know. Eval() is evil. If our answer is to use <a href="http://php.net/manual/en/function.eval.php">eval()</a> function, we are probably asking the wrong question. When we see an eval() function all our coding smell's red lights start flashing inside our mind. Definitely it's a bad practice. But last week I was thinking about it. How can I eval raw PHP code without using the eval function, and I will show you my outcomes.
</blockquote>
<p>
He includes some sample code showing a basic script with a class and a loop executing normally, then an "eval version" that puts it all in a string and executes it. He offers a different method - not an ideal one since it requires being able to write to the local file system, but prevents the need for eval - writing the PHP code to a temporary file and using a "fake eval" to <a href="htttp://php.net/include">pull it in</a>.
</p>]]></description>
      <pubDate>Tue, 13 Mar 2012 10:09:52 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Brandon Savage's Blog: An XSS Vulerability In The Making]]></title>
      <guid>http://www.phpdeveloper.org/news/17640</guid>
      <link>http://www.phpdeveloper.org/news/17640</link>
      <description><![CDATA[<p>
<i>Brandon Savage</i> has a new post to his blog about what he calls a <a href="http://www.brandonsavage.net/an-xss-vulerability-in-the-making/">XSS vulnerability in the making</a>, something to watch out for when you're doing validation in PHP involving the possibility of numbers as strings.
</p>
<blockquote>
Back in September, <a href="https://crash-stats.mozilla.org/">Socorro</a> received a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=689675">security bug</a> relating to the method we were using for processing inputs for the duration of certain reports. The vulnerability included a proof of concept, with an alert box popping up on production when the link was followed. [...] I was quite surprised at the root cause of the vulnerability. We had opted to compare the incoming data against a known set of valid values - a common practice when whitelisting certain inputs. [...] As expected, when this [example] code is tested, a string of '3' and an integer of 3 work equally well, and a string of '5' and an integer of 5 fail equally. 
</blockquote>
<p>
This automatic casting that PHP does internally caused another issue as well - if the string passed in even started with a valid number from their whitelist set, it still passed.
</p>
<blockquote>
At first we thought this surely had to be a bug in PHP. However, Laura Thomson told me "If comparing two values, type juggling is performed first, which means that the string is converted to a number. This is done by <a href="http://us2.php.net/manual/en/language.types.string.php#language.types.string.conversion">taking the first number found in the string</a>. So this may be confusing/a quirk/a gotcha, but it isn't a bug." And she's right: this isn't a bug per se, but it's certainly an interesting "gotcha."
</blockquote>]]></description>
      <pubDate>Wed, 07 Mar 2012 12:02:46 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Refulz.com: The __toString() Method - Objects as Strings]]></title>
      <guid>http://www.phpdeveloper.org/news/17523</guid>
      <link>http://www.phpdeveloper.org/news/17523</link>
      <description><![CDATA[<p>
On the Refulz.com blog there's a <a href="http://php.refulz.com/magic-methods-in-php-tostring-method/">recent post</a> introducing the __toString() magic method in PHP. This handy method allows you to define how to return an object when it's referenced as a string.
</p>
<blockquote>
We started the study of PHP magic methods by learning about <a href="http://php.refulz.com/magic-methods-in-php-__get-method/">__get() magic method</a>. [...] PHP is loosely typed language and same variable can be used or referred as string, number or object. The __toString() method is called when the code attempts to treat an object like a string. This function does not accept any arguments and should return a string.
</blockquote>
<p>
Some quick code is included showing how it works - returning a combined string made from two private class properties when the object ($obj) is echoed out. They also show multiple ways of using the method in both pre- and post-PHP 5.2.
</p>]]></description>
      <pubDate>Thu, 09 Feb 2012 09:27:19 -0600</pubDate>
    </item>
  </channel>
</rss>
