<?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: The Problem With &#8216;extract&#8217;</title>
	<atom:link href="http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Mon, 23 Nov 2009 05:10:48 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Design By Tim &#187; Blog Archive &#187; Rethinking extract() By Convention</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-12946</link>
		<dc:creator>Design By Tim &#187; Blog Archive &#187; Rethinking extract() By Convention</dc:creator>
		<pubDate>Fri, 20 Jan 2006 13:53:27 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-12946</guid>
		<description>[...] Since posting Learn To extract(); I have gotten a lot of great criticism that has helped me revise my thinking of the uses for extract(). Along with reading The Problem With ‘extract’ on SitePoint - here is my conclusion to when/where to use extract. Thanks to Danny, Oscar, Sandy, Ed, and Mitchell for their insights on the proper use of extract(). [...]</description>
		<content:encoded><![CDATA[<p>[...] Since posting Learn To extract(); I have gotten a lot of great criticism that has helped me revise my thinking of the uses for extract(). Along with reading The Problem With ‘extract’ on SitePoint &#8211; here is my conclusion to when/where to use extract. Thanks to Danny, Oscar, Sandy, Ed, and Mitchell for their insights on the proper use of extract(). [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: SitePoint Blogs &#187; Blog Archive &#187; How Readable is Your PHP?</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-8258</link>
		<dc:creator>SitePoint Blogs &#187; Blog Archive &#187; How Readable is Your PHP?</dc:creator>
		<pubDate>Thu, 25 Aug 2005 05:03:36 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-8258</guid>
		<description>[...] One of the entries is titled Every variable should start somewhere. In a previous blog post, I mentioned how frustrating it was to be trying to read some code and asking yourself, &#8216;Where does this variable come from?!&#8217;. Alan labels PHP language constructs such as extract and eval as &#8216;evil&#8217; because they disguise and obfuscate code. That isn&#8217;t news. However he makes a valid point&#8211;that using these types of shortcuts is not a security problem in itself&#8211;the security problem occurs when your code is too hard to understand and you inadvertently introduce additional problems. [...]</description>
		<content:encoded><![CDATA[<p>[...] One of the entries is titled Every variable should start somewhere. In a previous blog post, I mentioned how frustrating it was to be trying to read some code and asking yourself, &#8216;Where does this variable come from?!&#8217;. Alan labels PHP language constructs such as extract and eval as &#8216;evil&#8217; because they disguise and obfuscate code. That isn&#8217;t news. However he makes a valid point&#8211;that using these types of shortcuts is not a security problem in itself&#8211;the security problem occurs when your code is too hard to understand and you inadvertently introduce additional problems. [...]</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Vaska</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-8185</link>
		<dc:creator>Vaska</dc:creator>
		<pubDate>Sun, 21 Aug 2005 11:39:25 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-8185</guid>
		<description>I was THE particular author and I made a mistake.  Writing that article got a little messy as originally it wanted to be something else.  As you will notice, we pulled tip #5 from part two as it never should have been there...there was already a tip #5 in part one.  Originally there were 15 tips and my plan was to use the best 10.

As the previous poster surmises, I too believe that extract() is best used &#039;under controlled cirucumstances&#039;.  The example that I gave, with globals, was simply not a good one.

One of the things that I really valued a few years ago (well, I still do) are the discussions surrounding proper and improper use of various concepts.  It&#039;s darn informative - if you can follow along.  Originally, the article in question had a working title of &#039;Problems of Style&#039; that wanted to point out these things (the 10 tips) so that newbs could better recognize the variations because everybody does things slightly differently.  However, some methods are certainly better than others.  ;)</description>
		<content:encoded><![CDATA[<p>I was THE particular author and I made a mistake.  Writing that article got a little messy as originally it wanted to be something else.  As you will notice, we pulled tip #5 from part two as it never should have been there&#8230;there was already a tip #5 in part one.  Originally there were 15 tips and my plan was to use the best 10.</p>
<p>As the previous poster surmises, I too believe that extract() is best used &#8216;under controlled cirucumstances&#8217;.  The example that I gave, with globals, was simply not a good one.</p>
<p>One of the things that I really valued a few years ago (well, I still do) are the discussions surrounding proper and improper use of various concepts.  It&#8217;s darn informative &#8211; if you can follow along.  Originally, the article in question had a working title of &#8216;Problems of Style&#8217; that wanted to point out these things (the 10 tips) so that newbs could better recognize the variations because everybody does things slightly differently.  However, some methods are certainly better than others.  ;)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dorsey</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-8164</link>
		<dc:creator>Dorsey</dc:creator>
		<pubDate>Sat, 20 Aug 2005 01:53:27 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-8164</guid>
		<description>I use extract() under controlled conditions such as the previous one, where I&#039;m putting the values from a result set into local variables for convenience.  I fail to see the confusion here:  the SELECT statement clearly lists the variable names; my old buddy extract() saves me the effort of decorating the variable names with $row[&#039;column_name&#039;] everywhere.  I do NOT use this on any of the globals, as I said, but only under controlled circumstances, and enjoy the convenience it offers.</description>
		<content:encoded><![CDATA[<p>I use extract() under controlled conditions such as the previous one, where I&#8217;m putting the values from a result set into local variables for convenience.  I fail to see the confusion here:  the SELECT statement clearly lists the variable names; my old buddy extract() saves me the effort of decorating the variable names with $row['column_name'] everywhere.  I do NOT use this on any of the globals, as I said, but only under controlled circumstances, and enjoy the convenience it offers.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ramon Sosa</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-8149</link>
		<dc:creator>Ramon Sosa</dc:creator>
		<pubDate>Fri, 19 Aug 2005 15:39:52 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-8149</guid>
		<description>I personally use extract in:
1){
   while($row=mysql_fetch_assoc($result)){
      extract($row);
      include &#039;letter_to_clients_tpl.php&#039;;
   }

}
?&gt;

///letter_to_clients_tpl.php
//Begin Template

Dear customer:



Some notificacions.

Sincerely..

//End template</description>
		<content:encoded><![CDATA[<p>I personally use extract in:<br />
1){<br />
   while($row=mysql_fetch_assoc($result)){<br />
      extract($row);<br />
      include &#8216;letter_to_clients_tpl.php&#8217;;<br />
   }</p>
<p>}<br />
?&gt;</p>
<p>///letter_to_clients_tpl.php<br />
//Begin Template</p>
<p>Dear customer:</p>
<p>Some notificacions.</p>
<p>Sincerely..</p>
<p>//End template</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Etnu</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-2385</link>
		<dc:creator>Etnu</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-2385</guid>
		<description>&lt;p&gt;I&#039;ve been hard pressed to find any real reason why you&#039;d want to use extract, as it really doesn&#039;t gain you anything. Sure, it might be less to type out ($Variable vs. $Array[&#039;Variable&#039;]), but is it really worth all the confusion?&lt;/p&gt;

&lt;p&gt;There is only one practical use that I can think of, and that&#039;s if you pass arguments into a function in the form of an array (because you&#039;ve got a ton of parameters). Something like:&lt;/p&gt;

&lt;code lang=&quot;php&quot;&gt;
function DoStuff($Args)
{
  $FirstArg = 0;
  $SecondArg = &#039;&#039;;
  $ThirdArg = null;
  ...
  $ArgumentNumberTwenty = &#039;Wow!&#039;;
  extract($Args,EXTR_IF_EXISTS)
  ...
}&lt;/code&gt;&lt;p&gt;This would save the hassle of having to use isset() on each array element. Of course, you could also achieve this same thing using array_merge with the overwrite flag set, but that&#039;s just a matter of style preference.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been hard pressed to find any real reason why you&#8217;d want to use extract, as it really doesn&#8217;t gain you anything. Sure, it might be less to type out ($Variable vs. $Array['Variable']), but is it really worth all the confusion?</p>
<p>There is only one practical use that I can think of, and that&#8217;s if you pass arguments into a function in the form of an array (because you&#8217;ve got a ton of parameters). Something like:</p>
<p><code lang="php">
function DoStuff($Args)
{
  $FirstArg = 0;
  $SecondArg = '';
  $ThirdArg = null;
  ...
  $ArgumentNumberTwenty = 'Wow!';
  extract($Args,EXTR_IF_EXISTS)
  ...
}</code>
</p><p>This would save the hassle of having to use isset() on each array element. Of course, you could also achieve this same thing using array_merge with the overwrite flag set, but that&#8217;s just a matter of style preference.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Dr Livingston</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-2386</link>
		<dc:creator>Dr Livingston</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-2386</guid>
		<description>&lt;p&gt;Much like eval() I have never used extract() either. Wouldn&#039;t touch them with a barge pole, but I thank you for being it to the attention of other developers who may be using extract() without knowingly introduce a security hole in their scripts.&lt;/p&gt;

&lt;p&gt;My thoughts are just to ignore these two functions, as there are other alternatives and work arounds you can use, just as cleanly :)&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Much like eval() I have never used extract() either. Wouldn&#8217;t touch them with a barge pole, but I thank you for being it to the attention of other developers who may be using extract() without knowingly introduce a security hole in their scripts.</p>
<p>My thoughts are just to ignore these two functions, as there are other alternatives and work arounds you can use, just as cleanly :)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Willbanks</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-2387</link>
		<dc:creator>Mike Willbanks</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-2387</guid>
		<description>&lt;p&gt;Actually there is a very good use for extract that many people do not see...&lt;br /&gt;
If you built a template system there is an extremely good use.&lt;/p&gt;

&lt;p&gt;My templates simply work by running a page and extracting the variables to it...&lt;br /&gt;
Such as this:&lt;br /&gt;
$tpl-&gt;SetVariable(&#039;something&#039;, $somevar);&lt;br /&gt;
now what happens is during the template loading (they are simply php templates.. you can run php but it is in a sandbox so to speak) and the variables that have been set are extracted to it.&lt;/p&gt;

&lt;p&gt;But indeed you have to set your own variables to make it work.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Actually there is a very good use for extract that many people do not see&#8230;<br />
If you built a template system there is an extremely good use.</p>
<p>My templates simply work by running a page and extracting the variables to it&#8230;<br />
Such as this:<br />
$tpl->SetVariable(&#8217;something&#8217;, $somevar);<br />
now what happens is during the template loading (they are simply php templates.. you can run php but it is in a sandbox so to speak) and the variables that have been set are extracted to it.</p>
<p>But indeed you have to set your own variables to make it work.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: mwmitchell</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-2388</link>
		<dc:creator>mwmitchell</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-2388</guid>
		<description>&lt;p&gt;Hmm, OK one good use: If you have a PHP based template class. In the method that actually includes the template file... If you use extract (extract($this-&gt;template_data)), then you expose only the variables needed. If you use a loop, then you expose the $key/$val variables to the templates variable scope. What happens if someone has assigned a variable named &#039;key&#039; or &#039;val&#039;? It gets squashed by your foreach loop. Not with extract().&lt;/p&gt;

&lt;p&gt;Matt&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Hmm, OK one good use: If you have a PHP based template class. In the method that actually includes the template file&#8230; If you use extract (extract($this->template_data)), then you expose only the variables needed. If you use a loop, then you expose the $key/$val variables to the templates variable scope. What happens if someone has assigned a variable named &#8216;key&#8217; or &#8216;val&#8217;? It gets squashed by your foreach loop. Not with extract().</p>
<p>Matt</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Sketch</title>
		<link>http://www.sitepoint.com/blogs/2005/08/15/the-problem-with-extract/comment-page-1/#comment-2389</link>
		<dc:creator>Sketch</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">1662916895#comment-2389</guid>
		<description>&lt;p&gt;Not to mention that extract() is implicitly identical to setting register_globals to enabled.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Not to mention that extract() is implicitly identical to setting register_globals to enabled.</p>]]></content:encoded>
	</item>
</channel>
</rss>
