<?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, 22 May 2013 12:01:18 -0500</pubDate>
    <ttl>30</ttl>
    <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[Sebastian Bergmann's Blog: Scalar Type Hints in PHP 5.3.99]]></title>
      <guid>http://www.phpdeveloper.org/news/15484</guid>
      <link>http://www.phpdeveloper.org/news/15484</link>
      <description><![CDATA[<p>
In the theme of <a href="http://phpdeveloper.org/news/15476">other recent posts</a> mentioning the scalar type hinting that has been included in the main line of code that is headed towards the next PHP release, <i>Sebastian Bergmann</i> <a href="http://sebastian-bergmann.de/archives/900-Scalar-Type-Hints-in-PHP-5.3.99.html">has a new post</a> about their inclusion in PHP 5.3.99 (yes, that's PHP 5.4) and the new syntax it introduces.
</p>
<blockquote>
In a nutshell, this means that PHP 5.3.99 introduces new syntax -- scalar type hints -- but no new semantics. The latter can either be implemented as an extension written in C/C++, in userland PHP code, or in a tool that statically analyzes the code.
</blockquote>
<p>
He includes an example fro userland with a "php_check_parameters" function that looks at the arguments of the current method and uses <a href="http://php.net/reflection">Reflection</a> to check against the type hints for the correct value type.
</p>]]></description>
      <pubDate>Wed, 24 Nov 2010 10:04:06 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Johannes Schluter's Blog: More on scalar type hints in PHP trunk]]></title>
      <guid>http://www.phpdeveloper.org/news/15476</guid>
      <link>http://www.phpdeveloper.org/news/15476</link>
      <description><![CDATA[<p>
<i>Johannes Schluter</i> has <a href="http://schlueters.de/blog/archives/148-More-on-scalar-type-hints-in-PHP-trunk.html">posted a bit more information</a> about the scalar type hinting that's been included in the main development line of the PHP language (trunk).
</p>
<blockquote>
Some time ago I wrote an article about the implementation of type hints for non-object types for PHP. Meanwhile many things happened and that implementation was replaced by a different one. Readers of my previous post might know that I have doubts about type hints in PHP.
</blockquote>
<p>
He shows some of the example syntax for the hinting and points out how, in one case, there's no error thrown when the type hint is a native one but an error is thrown on a custom type hint. 
</p>
<blockquote>
So why is there a syntax added which is ignored? [...] Well, I let it to you to decide whether it make sense to have two syntaxes which look the same but do very different things (being ignored vs. throwing a terminating error) and whether it makes sense to push a system where the core language behaves differently depending on the system. [...] I seriously hoped PHP was out of the era of introducing new inconsistencies.
</blockquote>]]></description>
      <pubDate>Tue, 23 Nov 2010 09:13:24 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Johannes Schluter's Blog: Scalar type hints in PHP trunk]]></title>
      <guid>http://www.phpdeveloper.org/news/14923</guid>
      <link>http://www.phpdeveloper.org/news/14923</link>
      <description><![CDATA[<p>
As <i>Johannes Schluter</i> mentions in his <a href="http://schlueters.de/blog/archives/139-Scalar-type-hints-in-PHP-trunk.html">latest blog post</a>, another new feature has been added to the trunk of the PHP project - scalar type hints.
</p>
<blockquote>
So in my blog series I try to cover all additions to PHP trunk so I have to mention scalar type hints.
</blockquote>
<p>
He gives examples of both simple hinting (ensuring a value is a float) and a more complex example setting an attribute on a PDO connection (checking for an integer). Sample error messages are included as well. He also gives some advice on mixing strong and weak typing in your apps - it's like "opening a can of worms".
</p>]]></description>
      <pubDate>Mon, 09 Aug 2010 08:44:23 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Patrick Allaert's Blog: Readable PHP code #2 - Make your API handle more!]]></title>
      <guid>http://www.phpdeveloper.org/news/14572</guid>
      <link>http://www.phpdeveloper.org/news/14572</link>
      <description><![CDATA[<p>
In a new post today <i>Patrick Allaert</i> has continued his "Readable Code" series with some tips on how you can make your <a href="http://patrickallaert.blogspot.com/2010/05/readable-php-code-2-make-your-api.html">API handle more</a>.
</p>
<p>
His suggestions include:
</p>
<ul>
<li>Changing the handling to look for multiples by default
<li>Avoiding inner looping (repeated looping) and try for code reuse
<li>Transforming a scalar value into an array to make it easier to handle this way (by casting)
<li>and how to handle objects in the same array-handling kind of code
</ul>
<p>
He also tosses in a little mention of performance, noting that a call with <a href="http://php.net/range">range</a> in the argument to his array-handling method is faster than looping over the same range and calling the method each time.
</p>]]></description>
      <pubDate>Fri, 28 May 2010 08:41:22 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Ilia Alshanetsky's Blog: Scalar Type Hints are Here!]]></title>
      <guid>http://www.phpdeveloper.org/news/14547</guid>
      <link>http://www.phpdeveloper.org/news/14547</link>
      <description><![CDATA[<p>
<i>Ilia Alshanetsky</i> has a quick new post with some great news for some PHP developers out there - scalar type hinting has been introduced into the latest trunk of the PHP project.
</p>
<blockquote>
About an hour ago, something I've been fighting for almost 2 years happened. The Scalar Type Hinting patch for PHP (<a href="http://ilia.ws/patch/type_hint_final.txt">the one I wrote almost a year ago</a>) has been adjusted for PHP's trunk tree and <a href="http://svn.php.net/viewvc?view=revision&revision=299534">committed</a> by <a href="http://derickrethans.nl/">Derick</a>.
</blockquote>
<p>
You can see some of the type hinting features already included in PHP in <a href="http://php.net/manual/en/language.oop5.typehinting.php">the manual</a>. This patch adds hinting ability for the other (non-object and non-array) variable types.
</p>]]></description>
      <pubDate>Mon, 24 May 2010 11:48:19 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Ilia Alshanetsky's Blog: Type hinting for PHP 5.3]]></title>
      <guid>http://www.phpdeveloper.org/news/12798</guid>
      <link>http://www.phpdeveloper.org/news/12798</link>
      <description><![CDATA[<p>
One of the features included in the PHP 5.x releases is type hinting for validating that you have the right values for your functions and methods coming in. In <a href="http://ilia.ws/archives/205-Type-hinting-for-PHP-5.3.html">this new post</a> to his blog <i>Ilia Alshanetshy</i> takes a look at the the feature and gives a patch to add it .
</p>
<blockquote>
On a general level most people agree it would be a good idea to have, since it is an optional feature and does not introduce any regressions, heck you can even mix type hinted code with the non-type hinted one. The "PROBLEM" has always been combining of PHP's typeless nature with type hinting, which is where the consensus has been difficult (impossible) to reach.
</blockquote>
<p>
He mentions an example of why its such an issue (technically, both 1 and "1" are valid numbers) and includes <a href="http://ia.gd/patch/type_hint_53.txt">a link to a patch</a> that gives a new hint to help with the problem.
</p>]]></description>
      <pubDate>Thu, 02 Jul 2009 09:46:18 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHP in Action: Type hints are more useful for scalars than objects]]></title>
      <guid>http://www.phpdeveloper.org/news/11002</guid>
      <link>http://www.phpdeveloper.org/news/11002</link>
      <description><![CDATA[<p>
On the PHP in Action blog, there's a <a href="http://www.reiersol.com/blog/1_php_in_action/archive/160_type_hints_are_more_useful_for_scalars_than_objects.html">new post</a> looking at a <a href="http://www.maxhorvath.com/2008/09/type-hints-for-scalar-values-phptypesafe-10-rc2-released.html">recent library</a> that was posted to support type hinting on scalars. They agree with his choice of subjects, noting that they see type hinting as much more useful on scalars than on objects.
</p>
<blockquote>
I admit that these judgments are hard to make. I could be wrong, more or less. Type hints are probably useful when code becomes stable enough and at the boundaries between modules. But I still tend to avoid using them until I get an actual bug that might have been prevented by a type hint. Their usefulness is and has to be an empirical question. The purpose of using them has to be catching errors earlier, so if they don't have that effect, there's no point.
</blockquote>
<p>
He lists three reasons why he had given up on type hinting before, one being the limited usefulness when it came to objects. Applying it to scalars is a different matter, though, and can prevent improper passing of array/scalars when the other is needed.
</p>]]></description>
      <pubDate>Thu, 11 Sep 2008 10:08:33 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Derick Rethans' Blog: Scalar Type Hinting and DB Design Slides]]></title>
      <guid>http://www.phpdeveloper.org/news/5613</guid>
      <link>http://www.phpdeveloper.org/news/5613</link>
      <description><![CDATA[<p>
Derick Rethans has two blog posts for us today, <a href="http://derickrethans.nl/typehints_for_scalar_types.php">the first</a> details a <a href="http://files.derickrethans.nl/patches/ze-type-hint-2006-06-17.diff.txt">patch he created</a> which allows us to use type hints for all variable types in PHP.
</p>

<p>
Derick himself admits that its probably not the best approach:
</p>

<blockquote> 
The patch is most likely not the best way of implementing this either, and I am also not sure if this patch should be applied to PHP's CVS at all. 
</blockquote>

<p>
He offers the following as an example of how this would be used:
</p>

<blockquote>
<p>
function foo2( integer $i, float $f, bool $b ) { }
<br />
foo2( 'string', 42, 49.9 );
</p>

<p>
The example above should show:
</p>

<p>
Catchable fatal error: Argument 1 passed to foo2() must be of type integer, string given, called in /tmp/test.php on line 16 and defined in /tmp/test.php on line 12
</p>
</blockquote>

<p>
Derick also posted his <a href="http://derickrethans.nl/database_design_slides_finally.php">Database Design Slides</a> from his talk earlier this year at <a href="http://phparch.com">php|architects</a> php|tek
</p>]]></description>
      <pubDate>Sat, 17 Jun 2006 18:52:04 -0500</pubDate>
    </item>
  </channel>
</rss>
