<?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>Thu, 24 May 2012 18:26:30 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Anthony Ferrara's Blog: PHP's Source Code For PHP Developers - Part 3 - Variables]]></title>
      <guid>http://www.phpdeveloper.org/news/17711</guid>
      <link>http://www.phpdeveloper.org/news/17711</link>
      <description><![CDATA[<p>
The third part of the "PHP source for developers" series has been posted over on <i>Anthony Ferrara</i>'s blog today looking at <a href="http://blog.ircmaxell.com/2012/03/phps-source-code-for-php-developers_21.html">the variables PHP's internals use</a>.
</p>
<blockquote>
In this third post of the PHP's Source Code for PHP Developers series, we're going to expand on the prior posts to help understand how PHP works internally.  In the first post of the  series, we looked at how to view PHP's source code, how it's structured as well as some basic C pointers for PHP developers.  The second post introduced functions into the mix.  This time around, we're going to dive into one of the most useful structures in PHP: variables.
</blockquote>
<p>
He starts with one of the most important variable types used in PHP's source - the ZVAL. This is one of the keys to PHP's loose typing and can be thought of as "a class with only public properties". He gets into more detail with the properties of this "class" (value, refcount__gc, type and is_ref__gc). Also included is a look at how it's actually used - creating new ones, getting the value of them, converting their types and how the internal PHP functions parse their variables.
</p>
<p>
There's a lot more covered about variables in <a href="http://blog.ircmaxell.com/2012/03/phps-source-code-for-php-developers_21.html">the post</a> so if this is interesting stuff to you, be sure to read it all. They've done a great job of explaining one of the more complicated parts of the internals that power PHP.
</p>]]></description>
      <pubDate>Thu, 22 Mar 2012 08:30:45 -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[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[Nikita Popov's Blog: Scalar type hinting is harder than you think]]></title>
      <guid>http://www.phpdeveloper.org/news/17638</guid>
      <link>http://www.phpdeveloper.org/news/17638</link>
      <description><![CDATA[<p>
In <a href="http://nikic.github.com/2012/03/06/Scalar-type-hinting-is-harder-than-you-think">this new post</a> to his blog <i>Nikita</i> talks about scalar type hinting and why it's harder than most people think to accomplish.
</p>
<blockquote>
One of the features originally planned for PHP 5.4 was scalar type hinting. But as you know, they weren't included in the release. Recently the topic has come up again on the mailing list and there has been a hell lot of discussion about it. Yesterday ircmaxell published a <a href="http://blog.ircmaxell.com/2012/03/parameter-type-casting-in-php.html">blog post about his particular proposals</a>. The reactions on <a href="http://www.reddit.com/r/PHP/comments/qiniv/parameter_type_casting_in_php/">reddit</a> were mixed. On one hand it is clear that people do really want scalar type hints, on the other hand they didn't seem to like that particular proposal.
</blockquote>
<p>
He gets into some of the details of some of the current proposals and their problems like the strict versus loosely-typed nature of PHP and type hinting that was included but not enforced. One he does like, however, is one based on casting - how the variable ends up being cast rather than the specific type it is when it comes into the function/method. This one still has its flaws, so he suggests another method - weak type hints but with stricter input validation (without casting). He also briefly mentions something called "box based type hinting" that would allow users to define their own hinting rules.
</p>
<p>
Don't worry - code examples (pseudo-code obviously) <a href="http://nikic.github.com/2012/03/06/Scalar-type-hinting-is-harder-than-you-think">are included</a> for each of these proposals to help you understand the differences.
</p>]]></description>
      <pubDate>Wed, 07 Mar 2012 10:03:47 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Anthony Ferrara's Blog: Parameter Type Casting in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/17632</guid>
      <link>http://www.phpdeveloper.org/news/17632</link>
      <description><![CDATA[<p>
<i>Anthony Ferrara</i> has a new article posted to his site today about <a href="http://blog.ircmaxell.com/2012/03/parameter-type-casting-in-php.html">parameter typecasting</a> and the discussions that have been happening about it on the PHP "<a href="http://php.net/mailing-lists.php">internals</a>" mailing list.
</p>
<blockquote>
As any of you who follow the <a href="http://news.php.net/php.internals">PHP internals</a> list know, scalar type hinting has been a hot topic as of late.  You'll also know that I've submitted two new RFC (Request For Comment) proposals for inclusion of two new major features in the PHP language.  I figured it was worth going into both RFCs and patches a little deeper, explain my rationale and (hopefully) garner some more visibility of the proposals.
</blockquote>
<p>
He shares the details of the two main RFCs that are proposed right now - parameter type casting hints and object scalar casting magic methods (both with code examples). Right now, they're only in the patch stage and there's talk of improving the current casting functionality of PHP before something like one of these goes into place. 
</p>]]></description>
      <pubDate>Tue, 06 Mar 2012 11:05:32 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Type Hinting in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/17627</guid>
      <link>http://www.phpdeveloper.org/news/17627</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial posted about <a href="http://phpmaster.com/type-hinting-in-php/">using type hinting</a> in your PHP applications to restrict the values passed into your methods.
</p>
<blockquote>
Since PHP 5 you can use type hinting to specify the expected data type of an argument in a function declaration. When you call the function, PHP will check whether or not the arguments are of the specified type. If not, the run-time will raise an error and execution will be halted.
</blockquote>
<p>
Included in the post are code examples showing how to define custom types in a function definition and what happens if you pass the wrong type in. Also mentioned is one of the main limitations to hinting - the fact that it can't be used on default PHP variable types. 
</p>]]></description>
      <pubDate>Mon, 05 Mar 2012 13:19:24 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[C. Sadeesh Kumar's Blog: Smart File Type Detection Using PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16785</guid>
      <link>http://www.phpdeveloper.org/news/16785</link>
      <description><![CDATA[<p>
In a new post today <i>C. Sadeesh Kumar</i> has a quick tip to help your script <a href="http://cakephp-php.blogspot.com/2011/08/smart-file-type-detection-using-php.html">detect file types</a> without having to rely on the extension to be correct.
</p>
<blockquote>
In most web applications today, there is a need to allow users to upload images, audio and video files. Sometimes, we also need to restrict certain types of files from being uploaded - an executable file being an obvious example. Security aside, one might also want to prevent users from misusing the upload facility, e.g. uploading copyrighted music files illegally and using the service to promote piracy! In this article, we'll look into a few ways in which we can achieve this.
</blockquote>
<p>
The trick to his example is in using the <a href="http://pecl.php.net/package/Fileinfo">Fileinfo</a> PECL extension. With the help of this extension you can look inside the file and pick out the "magic bytes" (the first few bytes of a file) and see <a href="http://www.garykessler.net/library/file_sigs.html">what MIME type</a> the file really is. He includes a simple example of using the extension on a file and a file upload script that checks the type and handles the file accordingly.
</p>]]></description>
      <pubDate>Mon, 29 Aug 2011 12:07:53 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[WebTutor.pl: Strong data typing in PHP, part II: autoboxing and indestructable objects]]></title>
      <guid>http://www.phpdeveloper.org/news/16198</guid>
      <link>http://www.phpdeveloper.org/news/16198</link>
      <description><![CDATA[<p>
In the second part of their series looking at data typing in PHP, the WebTutor blog takes a different approach to supporting strong typing in PHP, using <a href="http://php.webtutor.pl/index.php/2011/04/13/strong-data-typing-in-php-part-ii-autoboxing-and-indestructable-objects-english-version/">autoboxing and indestructible objects</a>.
</p>
<blockquote>
In an earlier <a href="http://php.webtutor.pl/index.php/2011/03/23/silne-typowanie-danych-w-php-czesc-i/">article on the strong typing</a> I've described the typehint mechanism that provides data type enforcement for the values sent to the methods and functions. Unfortunately said implementation does not protect against another problem associated with the dynamic typing of variables: a lack of type enforcement when overwritting value of an existing variable. In order to control the type of data, I decided to introduce to PHP the concept of autoboxing known from other languages such as C# and Java.
</blockquote>
<p>
He talks briefly about what autoboxing is (wrapping primitive types into objects automatically) and links to <a href="http://webscripts.softpedia.com/script/PHP-Clases/Java-and-C--compatible-object-autoboxing-66176.html">a library</a> that can be used to accomplish it. A bit of sample code is included showing how to create an AutoBoxedObject and how to use it in practice on some string values.
</p>]]></description>
      <pubDate>Thu, 14 Apr 2011 12:09:40 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Christian Weiske's Blog: A MIME type for .php files]]></title>
      <guid>http://www.phpdeveloper.org/news/16195</guid>
      <link>http://www.phpdeveloper.org/news/16195</link>
      <description><![CDATA[<p>
<i>Christian Weiske</i> has a recent post to his site looking at something most PHP developers don't even think about when serving up their scripts - the <a href="http://cweiske.de/tagebuch/php-mimetype.htm">MIME types for PHP files</a>.
</p>
<blockquote>
While setting some svn properties at work, we wondered about the correct MIME type for .php files.
</blockquote>
<p>
He found several in the <a href="http://www.iana.org/assignments/media-types/">official IANA list</a> including "text/php", "application/php" and "application/x-http-php" - all valid but none of them considered a standard. He talks about the ones supported by linux distributions (like Debian/Ubuntu) and some reasoning that might make "application/php" the best choice of the list. He points out some downsides to the choice, though, including the fact that something starting with "application/" should considered "machine readable" only despite PHP just being text.
</p>]]></description>
      <pubDate>Thu, 14 Apr 2011 09:17:06 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Gonzalo Ayuso's Blog: Reflection over PHPDoc with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16143</guid>
      <link>http://www.phpdeveloper.org/news/16143</link>
      <description><![CDATA[<p>
<i>Gonzalo Ayuso</i> has a new post to his blog today talking about a regular expression-laden script he's some up with to <a href="http://gonzalo123.wordpress.com/2011/04/04/reflection-over-phpdoc-with-php/">reflect over a PHP file</a> and pull out the document's comments (PHPDoc-style).
</p>
<blockquote>
I want to parse PHPDoc code. Let me explain a little bit what I want to do. Imagine a dummy function documented with PHPDoc. [...] PHP has a great reflection API, but as at least in the current PHP version (as far as I know) we only can get the PHPDoc as a string, without parse it. I need to get the parameters and the type of them with reflection. [...] But the type is different. 
</blockquote>
<p>
His script (based loosely on a bit of a component from the <a href="http://framework.zend.com">Zend Framework</a>) parses the file and its comments and grabs the variable types from the PHPDoc blocks on each method and associates them.
</p>
<p>
If you're looking for a more mature solution than just this script, take a look at <a href="https://github.com/mvriel/Docblox">Docblox</a>, a PHP 5.3 documentation generator.
</p>]]></description>
      <pubDate>Mon, 04 Apr 2011 12:51:15 -0500</pubDate>
    </item>
  </channel>
</rss>

