<?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 20:15:16 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Jani Hartikainen's Blog: Practical uses for reflection]]></title>
      <guid>http://www.phpdeveloper.org/news/11961</guid>
      <link>http://www.phpdeveloper.org/news/11961</link>
      <description><![CDATA[<p>
<a href="http://php.net/reflection">Reflection</a> can be a handy tool when you need it, but how many times have you actually found a use for it in the past few applications you've written? <i>Jani Hartikainen</i> has <a href="http://codeutopia.net/blog/2009/02/16/practical-uses-for-reflection/">one suggestion</a> of a place it can be used - form generation.
</p>
<blockquote>
Most web applications use forms. Forms often represent some model, such as a news post. If the model is simple, writing the form in HTML is not too bad, or we might be able to use a scaffolding feature in our framework. [...] Here's a good use for reflection! Since in models we often have a naming scheme for the data the users would be able to input, we can utilize this knowledge with reflection to generate a list of possible fields in the model, and then generate the form with less typing required from us.
</blockquote>
<p>
His example looks into the model class and pulls out the "get" functions and, after pulling out the name, adds it to a fields array. This array is then passed out to the display part of the script and looped over to create a text field for each. He expands it a bit to also include checking for "@return" values in docblock comments for the type of form field that should be displayed.
</p>]]></description>
      <pubDate>Tue, 17 Feb 2009 10:22:36 -0600</pubDate>
    </item>
  </channel>
</rss>
