<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" 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/" > <channel><title>Comments on: 6 Signs of Adaptive PHP</title> <atom:link href="http://brenelz.com/blog/6-signs-of-adaptive-php/feed/" rel="self" type="application/rss+xml" /><link>http://brenelz.com/blog/6-signs-of-adaptive-php/</link> <description>a winnipeg website design company.</description> <lastBuildDate>Thu, 29 Jul 2010 18:34:25 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>By: Kevin</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-736</link> <dc:creator>Kevin</dc:creator> <pubDate>Sun, 12 Apr 2009 07:06:17 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-736</guid> <description>I thought these were some great tips to consider. I&#039;ve found that using empty() can be a little tricky sometimes. What works for me is to trim() the value first then test for strlen().  The the value is NULL or is bool FALSE, then it will have a string length of zero. Even if the value is 0, then it will at least have a string length of 1 and you know you have something. You can do further test from there. I&#039;m not php expert, but it clears up confusion for me.</description> <content:encoded><![CDATA[<p>I thought these were some great tips to consider. I&#8217;ve found that using empty() can be a little tricky sometimes. What works for me is to trim() the value first then test for strlen().  The the value is NULL or is bool FALSE, then it will have a string length of zero. Even if the value is 0, then it will at least have a string length of 1 and you know you have something. You can do further test from there. I&#8217;m not php expert, but it clears up confusion for me.</p> ]]></content:encoded> </item> <item><title>By: Kaloyan K. Tsvetkov</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-729</link> <dc:creator>Kaloyan K. Tsvetkov</dc:creator> <pubDate>Wed, 11 Mar 2009 21:16:14 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-729</guid> <description>Man, where did you learned all that stuff. It&#039;s crap ;) You lost me on #1. First, don&#039;t use &lt;code&gt;empty()&lt;/code&gt; for array elements which might now be there -- use &lt;code&gt;isset()&lt;/code&gt; instead ! If you use &lt;code&gt;empty()&lt;/code&gt; in E_ALL error reporting (as we all should do), you will get the penalty of a friendly warning that the array element is not set for you to check it. Second, this is too much overkill. Even the &lt;code&gt;array_merge()&lt;/code&gt; is too much code for me ;) You can do everything a lot easier:&lt;code&gt;$arg = $arg + array(&#039;hoho&#039; =&gt; &#039;default value 1&#039;, &#039;hehe&#039; =&gt; &#039;default value 2&#039;);&lt;/code&gt;You know that you can do union like this, right ? If not, read the PHP manual again:http://php.net/manual/en/language.operators.array.php</description> <content:encoded><![CDATA[<p>Man, where did you learned all that stuff. It&#8217;s crap <img src='http://cdnwww.brenelz.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> You lost me on #1. First, don&#8217;t use <code>empty()</code> for array elements which might now be there &#8212; use <code>isset()</code> instead ! If you use <code>empty()</code> in E_ALL error reporting (as we all should do), you will get the penalty of a friendly warning that the array element is not set for you to check it. Second, this is too much overkill. Even the <code>array_merge()</code> is too much code for me <img src='http://cdnwww.brenelz.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> You can do everything a lot easier:</p><p><code>$arg = $arg + array('hoho' =&gt; 'default value 1', 'hehe' =&gt; 'default value 2');</code></p><p>You know that you can do union like this, right ? If not, read the PHP manual again:</p><p><a href="http://php.net/manual/en/language.operators.array.php" rel="nofollow">http://php.net/manual/en/language.operators.array.php</a></p> ]]></content:encoded> </item> <item><title>By: Pras Sarkar</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-727</link> <dc:creator>Pras Sarkar</dc:creator> <pubDate>Wed, 11 Mar 2009 18:20:32 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-727</guid> <description>This is a good article of quick and practical tips, but there are some caveats to using them.1. Using an associative array is fine, but remember that functions are APIs. If you&#039;re working on a project with others, you&#039;ll want them to find out the arguments and datatypes for those arguments by looking at your function definition. You lose this clarity when you clump everything into an associative array. There are uses for this, just not everywhere.3. Definitely a good tip. A minor caveat is that require_once() is slower than require() since it needs an additional hash lookup to see if the file has been included before.4. Again, similar drawbacks to #1, since now any changes you make to the returning associative array has the potential to break code that&#039;s relying on the returned variables.PHP is a great flexible language with a lot of power. But with that power comes responsibility to stick to best practices (and break them only in special circumstances).</description> <content:encoded><![CDATA[<p>This is a good article of quick and practical tips, but there are some caveats to using them.</p><p>1. Using an associative array is fine, but remember that functions are APIs. If you&#8217;re working on a project with others, you&#8217;ll want them to find out the arguments and datatypes for those arguments by looking at your function definition. You lose this clarity when you clump everything into an associative array. There are uses for this, just not everywhere.</p><p>3. Definitely a good tip. A minor caveat is that require_once() is slower than require() since it needs an additional hash lookup to see if the file has been included before.</p><p>4. Again, similar drawbacks to #1, since now any changes you make to the returning associative array has the potential to break code that&#8217;s relying on the returned variables.</p><p>PHP is a great flexible language with a lot of power. But with that power comes responsibility to stick to best practices (and break them only in special circumstances).</p> ]]></content:encoded> </item> <item><title>By: Jack Timmons</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-725</link> <dc:creator>Jack Timmons</dc:creator> <pubDate>Wed, 11 Mar 2009 18:12:59 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-725</guid> <description>Most of the comments against the ideas are valid, and using __get and __set shouldn&#039;t even be used except in controlled situations. I&#039;m going on the premise that they are in said situation. All I use __get and __set for are autoloading column names from a database to help addons later.</description> <content:encoded><![CDATA[<p>Most of the comments against the ideas are valid, and using __get and __set shouldn&#8217;t even be used except in controlled situations. I&#8217;m going on the premise that they are in said situation. All I use __get and __set for are autoloading column names from a database to help addons later.</p> ]]></content:encoded> </item> <item><title>By: Jack Timmons</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-724</link> <dc:creator>Jack Timmons</dc:creator> <pubDate>Wed, 11 Mar 2009 17:08:21 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-724</guid> <description>How can you overlook __get and __set, yet include __autoload? ;)If you&#039;re talking about having adaptive PHP, you should really encourage your followers to define a storage array so they can dynamically store variables using __get and __set.</description> <content:encoded><![CDATA[<p>How can you overlook __get and __set, yet include __autoload? <img src='http://cdnwww.brenelz.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>If you&#8217;re talking about having adaptive PHP, you should really encourage your followers to define a storage array so they can dynamically store variables using __get and __set.</p> ]]></content:encoded> </item> <item><title>By: Pete W</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-722</link> <dc:creator>Pete W</dc:creator> <pubDate>Wed, 11 Mar 2009 06:37:49 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-722</guid> <description>function foo ( array $args ) { $vars = array( &#039;apple&#039; =&gt; &#039;default&#039;, &#039;banana&#039; =&gt; &#039;values&#039;, &#039;orange&#039; =&gt; &#039;&#039;, );$merged = array_merge($vars, $args); extract(array_intersect_key($merged, $vars)); unset($merged, $vars); //code rest of function ... }</description> <content:encoded><![CDATA[<p>function foo ( array $args )<br /> {<br /> $vars = array(<br /> &#8216;apple&#8217; =&gt; &#8216;default&#8217;,<br /> &#8216;banana&#8217; =&gt; &#8216;values&#8217;,<br /> &#8216;orange&#8217; =&gt; &#8221;,<br /> );</p><p> $merged = array_merge($vars, $args);<br /> extract(array_intersect_key($merged, $vars));<br /> unset($merged, $vars);<br /> //code rest of function &#8230;<br /> }</p> ]]></content:encoded> </item> <item><title>By: Pete W</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-721</link> <dc:creator>Pete W</dc:creator> <pubDate>Wed, 11 Mar 2009 06:31:45 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-721</guid> <description>/* * Until we have 5.3 */ if ( !defined(&#039;__DIR__&#039;) ) { define(&#039;__DIR__&#039;, dirname(__FILE__)); }</description> <content:encoded><![CDATA[<p>/*<br /> * Until we have 5.3<br /> */<br /> if ( !defined(&#8216;__DIR__&#8217;) ) {<br /> define(&#8216;__DIR__&#8217;, dirname(__FILE__));<br /> }</p> ]]></content:encoded> </item> <item><title>By: Shuja Shabandri</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-720</link> <dc:creator>Shuja Shabandri</dc:creator> <pubDate>Wed, 11 Mar 2009 06:21:18 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-720</guid> <description>I think setting defaults can be done in a better way.$defaults = array(&#039;hehe&#039; =&gt; &#039;default hehe&#039;, &#039;hoho&#039; =&gt; &#039;default hoho&#039;);$args = array_merge($defaults,$args);This avoids a long list of isset or empty checks for all params.</description> <content:encoded><![CDATA[<p>I think setting defaults can be done in a better way.</p><p>$defaults = array(&#8216;hehe&#8217; =&gt; &#8216;default hehe&#8217;, &#8216;hoho&#8217; =&gt; &#8216;default hoho&#8217;);</p><p>$args = array_merge($defaults,$args);</p><p>This avoids a long list of isset or empty checks for all params.</p> ]]></content:encoded> </item> <item><title>By: Best of the Web: February - NETTUTS</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-718</link> <dc:creator>Best of the Web: February - NETTUTS</dc:creator> <pubDate>Tue, 10 Mar 2009 13:11:28 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-718</guid> <description>[...] Visit Article [...]</description> <content:encoded><![CDATA[<p>[...] Visit Article [...]</p> ]]></content:encoded> </item> <item><title>By: Giorgio Sironi</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-717</link> <dc:creator>Giorgio Sironi</dc:creator> <pubDate>Sun, 08 Mar 2009 22:00:31 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-717</guid> <description>I guess #6 is &quot;Allows files to be Included around on the server without problems&quot; (however is __FILE__). The __FILE__ magic constant is a string containing the script filename and is substituted on compilation, so if you do an include a file that contains #6 code, the require_once will continue to work even if your client file is in another folder.</description> <content:encoded><![CDATA[<p>I guess #6 is &#8220;Allows files to be Included around on the server without problems&#8221; (however is __FILE__).<br /> The __FILE__ magic constant is a string containing the script filename and is substituted on compilation, so if you do an include a file that contains #6 code, the require_once will continue to work even if your client file is in another folder.</p> ]]></content:encoded> </item> <item><title>By: 網站製作學習誌 &#187; [Web] 連結分享</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-719</link> <dc:creator>網站製作學習誌 &#187; [Web] 連結分享</dc:creator> <pubDate>Sun, 08 Mar 2009 08:28:44 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-719</guid> <description>[...] 6 Signs of Adaptive PHP [...]</description> <content:encoded><![CDATA[<p>[...] 6 Signs of Adaptive PHP [...]</p> ]]></content:encoded> </item> <item><title>By: Matt</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-735</link> <dc:creator>Matt</dc:creator> <pubDate>Fri, 06 Mar 2009 13:52:01 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-735</guid> <description>I couldn&#039;t disagree more with your first point.  It increases your ability to add arbitrary function arguments - which is of arguable benefit - at the cost of clarity in code.  You should use whatever data structure is appropriate for the required arguments.  If it&#039;s an integer, use an integer.  You don&#039;t need to wrap it in an array.As for point 3, this is solved through a sane include strategy, such as bootstrapping, that better structures your code.  If you find yourself getting errors because you include the same file more than once, that&#039;s a code smell, and a sign you need to reconsider your organization.</description> <content:encoded><![CDATA[<p>I couldn&#8217;t disagree more with your first point.  It increases your ability to add arbitrary function arguments &#8211; which is of arguable benefit &#8211; at the cost of clarity in code.  You should use whatever data structure is appropriate for the required arguments.  If it&#8217;s an integer, use an integer.  You don&#8217;t need to wrap it in an array.</p><p>As for point 3, this is solved through a sane include strategy, such as bootstrapping, that better structures your code.  If you find yourself getting errors because you include the same file more than once, that&#8217;s a code smell, and a sign you need to reconsider your organization.</p> ]]></content:encoded> </item> <item><title>By: Matías</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-734</link> <dc:creator>Matías</dc:creator> <pubDate>Fri, 06 Mar 2009 12:06:18 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-734</guid> <description>Nice :)</description> <content:encoded><![CDATA[<p>Nice <img src='http://cdnwww.brenelz.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: remy</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-733</link> <dc:creator>remy</dc:creator> <pubDate>Fri, 06 Mar 2009 11:27:48 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-733</guid> <description>i would advise the author to read up on design patterns. a different approach to for example #1 passing an array as a parameter could be this: http://sourcemaking.com/refactoring/introduce-parameter-object</description> <content:encoded><![CDATA[<p>i would advise the author to read up on design patterns. a different approach to for example #1 passing an array as a parameter could be this: <a href="http://sourcemaking.com/refactoring/introduce-parameter-object" rel="nofollow">http://sourcemaking.com/refactoring/introduce-parameter-object</a></p> ]]></content:encoded> </item> <item><title>By: Andrew Lim</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-732</link> <dc:creator>Andrew Lim</dc:creator> <pubDate>Fri, 06 Mar 2009 09:39:43 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-732</guid> <description>For tip #6, I think it should be __FILE__ with 2 underscores prefixed and suffixed instead of _FILE_.</description> <content:encoded><![CDATA[<p>For tip #6, I think it should be __FILE__ with 2 underscores prefixed and suffixed instead of _FILE_.</p> ]]></content:encoded> </item> <item><title>By: Pinderkent: "Adaptive PHP" techniques help ensure bugs, unmaintainability, and other problems.</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-731</link> <dc:creator>Pinderkent: "Adaptive PHP" techniques help ensure bugs, unmaintainability, and other problems.</dc:creator> <pubDate>Fri, 06 Mar 2009 02:51:39 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-731</guid> <description>[...] bugs, unmaintainability, and other problems.Posted on Friday, March 06, 2009 at 2:34 AM. The recent 6 Signs of Adaptive PHP article gives some examples of different PHP coding techniques. Unfortunately, it only bothers to [...]</description> <content:encoded><![CDATA[<p>[...] bugs, unmaintainability, and other problems.Posted on Friday, March 06, 2009 at 2:34 AM. The recent 6 Signs of Adaptive PHP article gives some examples of different PHP coding techniques. Unfortunately, it only bothers to [...]</p> ]]></content:encoded> </item> <item><title>By: Andrew</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-730</link> <dc:creator>Andrew</dc:creator> <pubDate>Fri, 06 Mar 2009 02:44:58 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-730</guid> <description>Wow, this is like the really half-assed shoot-yourself-in-the-foot version of best practices. All of these are based on good ideas, but (with the exception of 3) none of them are _actually_ a good way to do it.Using key/value pairs without discipline is a good way to turn an interface into mush.Using autoload is dangerous and should never be undertaken without knowing what you&#039;re doing -- an example as simple as the one here should never be used.Likewise with introspection -- it&#039;s a great idea but if you try to do anything as simple as the exists() examples here you&#039;re going to dig yourself some huge holes and create some very _interesting_ bugs.</description> <content:encoded><![CDATA[<p>Wow, this is like the really half-assed shoot-yourself-in-the-foot version of best practices. All of these are based on good ideas, but (with the exception of 3) none of them are _actually_ a good way to do it.</p><p>Using key/value pairs without discipline is a good way to turn an interface into mush.</p><p>Using autoload is dangerous and should never be undertaken without knowing what you&#8217;re doing &#8212; an example as simple as the one here should never be used.</p><p>Likewise with introspection &#8212; it&#8217;s a great idea but if you try to do anything as simple as the exists() examples here you&#8217;re going to dig yourself some huge holes and create some very _interesting_ bugs.</p> ]]></content:encoded> </item> <item><title>By: thepearson</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-728</link> <dc:creator>thepearson</dc:creator> <pubDate>Fri, 06 Mar 2009 00:15:21 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-728</guid> <description>#1 - You want to be careful when using arrays as &quot;catch all&quot; parameters in functions. While it does make for easy expansion, it obfuscates the interface from the client. Good post.</description> <content:encoded><![CDATA[<p>#1 &#8211; You want to be careful when using arrays as &#8220;catch all&#8221; parameters in functions. While it does make for easy expansion, it obfuscates the interface from the client. Good post.</p> ]]></content:encoded> </item> <item><title>By: david</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-726</link> <dc:creator>david</dc:creator> <pubDate>Thu, 05 Mar 2009 22:48:10 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-726</guid> <description>#4 : what is wrong with using list to identify the values from the returned array?</description> <content:encoded><![CDATA[<p>#4 : what is wrong with using list to identify the values from the returned array?</p> ]]></content:encoded> </item> <item><title>By: Dave</title><link>http://brenelz.com/blog/6-signs-of-adaptive-php/comment-page-1/#comment-723</link> <dc:creator>Dave</dc:creator> <pubDate>Thu, 05 Mar 2009 21:19:54 +0000</pubDate> <guid isPermaLink="false">http://www.brenelz.com/blog/?p=684#comment-723</guid> <description>@Steve Clay: additional gotcha to be careful of with isset() is for array values where the key=&gt;value pair can have a null value. Consider:$arr = array(); $arr[&#039;param&#039;] = null; if ( isset($arr[&#039;param&#039;]) ) { //do something }isset() will return false - even though the key does exist. If $arr[&#039;param&#039;] is false, 0, &#039;&#039; (empty string), isset() will return true.</description> <content:encoded><![CDATA[<p>@Steve Clay: additional gotcha to be careful of with isset() is for array values where the key=&gt;value pair can have a null value. Consider:</p><p>$arr = array();<br /> $arr['param'] = null;<br /> if ( isset($arr['param']) ) {<br /> //do something<br /> }</p><p>isset() will return false &#8211; even though the key does exist. If $arr['param'] is false, 0, &#8221; (empty string), isset() will return true.</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 4/29 queries in 0.136 seconds using disk
Content Delivery Network via cdnwww.brenelz.com

Served from: brenelz.com @ 2010-08-01 10:33:28 -->