<?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: PHP : Variables vs Constants</title>
	<atom:link href="http://planetozh.com/blog/2006/06/php-variables-vs-constants/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/?source=rss</link>
	<description>A bit of my personal life, mainly focused on my kids. A bit of code, mainly focused on Wordpress and PHP. Overall, bits of nothing in particular.</description>
	<lastBuildDate>Fri, 18 May 2012 15:58:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Okonomiyaki3000</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-197360</link>
		<dc:creator>Okonomiyaki3000</dc:creator>
		<pubDate>Fri, 16 Dec 2011 09:29:49 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-197360</guid>
		<description>Your test misses some key points that arise in reality. 

If you have certain values that will be the same throughout your application (configuration values for example) you will want to define them up front and then use them in various places, different scopes. To do this with variables, you&#039;d either need to make them global (gross) or create a class or function for accessing them. Then you have the overhead of making a function call every time you need one. This is surely slower than accessing a constant.

Also (and this is just speculation), I&#039;d expect that constants will have the edge when you&#039;re using APC which you should be using at all times.</description>
		<content:encoded><![CDATA[<p>Your test misses some key points that arise in reality. </p>
<p>If you have certain values that will be the same throughout your application (configuration values for example) you will want to define them up front and then use them in various places, different scopes. To do this with variables, you&#8217;d either need to make them global (gross) or create a class or function for accessing them. Then you have the overhead of making a function call every time you need one. This is surely slower than accessing a constant.</p>
<p>Also (and this is just speculation), I&#8217;d expect that constants will have the edge when you&#8217;re using APC which you should be using at all times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Keilaron</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-148580</link>
		<dc:creator>Keilaron</dc:creator>
		<pubDate>Wed, 30 Mar 2011 18:42:26 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-148580</guid>
		<description>Interesting anti-spam, but what kind of voodoo doll can you use if you don&#039;t know who spammed you?

Anyway, I realize this post is old, but I just ran a test seeing how fast constants and variables are *set*, nevermind retrieved or used, and felt like looking for similar information.
The results: With a million statements each, constants only took 4 seconds, whereas variable took 44 MINUTES to be set...
In other words, if you aren&#039;t going to change your values, you&#039;re saving a lot of time setting constants over variables.</description>
		<content:encoded><![CDATA[<p>Interesting anti-spam, but what kind of voodoo doll can you use if you don&#8217;t know who spammed you?</p>
<p>Anyway, I realize this post is old, but I just ran a test seeing how fast constants and variables are *set*, nevermind retrieved or used, and felt like looking for similar information.<br />
The results: With a million statements each, constants only took 4 seconds, whereas variable took 44 MINUTES to be set&#8230;<br />
In other words, if you aren&#8217;t going to change your values, you&#8217;re saving a lot of time setting constants over variables.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adriano</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-139771</link>
		<dc:creator>Adriano</dc:creator>
		<pubDate>Tue, 25 Jan 2011 20:56:23 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-139771</guid>
		<description>Wow, I&#039;m back to this page after years.

You know, I believe that it all depends on the hardware, probably variables are more subject to RAM, while contants to hard drive and cpu.

A</description>
		<content:encoded><![CDATA[<p>Wow, I&#8217;m back to this page after years.</p>
<p>You know, I believe that it all depends on the hardware, probably variables are more subject to RAM, while contants to hard drive and cpu.</p>
<p>A</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aleksej Ivanov</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-138618</link>
		<dc:creator>Aleksej Ivanov</dc:creator>
		<pubDate>Sun, 16 Jan 2011 21:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-138618</guid>
		<description>The test is completely incorrect. You&#039;ve used math functions, that works with &quot;coprocessor&quot;. Those functions cannot use constants so, the processor is performing a double job here. You are actually testing your processor. 
Try to test constants with integers or strings.</description>
		<content:encoded><![CDATA[<p>The test is completely incorrect. You&#8217;ve used math functions, that works with &#8220;coprocessor&#8221;. Those functions cannot use constants so, the processor is performing a double job here. You are actually testing your processor.<br />
Try to test constants with integers or strings.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ozh</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-102860</link>
		<dc:creator>Ozh</dc:creator>
		<pubDate>Fri, 09 Apr 2010 09:18:19 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-102860</guid>
		<description>Interesting take, Johan!</description>
		<content:encoded><![CDATA[<p>Interesting take, Johan!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-102854</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Fri, 09 Apr 2010 06:33:15 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-102854</guid>
		<description>You should also check the resources it takes, under default settings i ran the following test:

&lt;?php
$i = 0;
while(true){
	&lt;&lt;&gt;&gt;
	$i ++;
	echo $i, &quot;_&quot;;
}

where &lt;&lt;&gt;&gt; is the one of the code below, which followed by the highest value of $i I got,

define(&quot;var&quot;.$i, &quot;X&quot;);	// highest value of $i = 2091796
${&quot;var&quot;.$i} = &quot;X&quot;;	// highest value of $i =  217845
$var[] = &quot;X&quot;;		// highest value of $i =  245070
$var[][] = &quot;X&quot;;		// highest value of $i =   84420

While you showed that constants are the slowest, they are, by far, the least resource intensive,

suprising is that arrays are also less resource intensive then normal variables, even though this effect weakens with multi-demensional arrays</description>
		<content:encoded><![CDATA[<p>You should also check the resources it takes, under default settings i ran the following test:</p>
<p>&lt;?php<br />
$i = 0;<br />
while(true){<br />
	&lt;&lt;&gt;&gt;<br />
	$i ++;<br />
	echo $i, &#8220;_&#8221;;<br />
}</p>
<p>where &lt;&lt;&gt;&gt; is the one of the code below, which followed by the highest value of $i I got,</p>
<p>define(&#8220;var&#8221;.$i, &#8220;X&#8221;);	// highest value of $i = 2091796<br />
${&#8220;var&#8221;.$i} = &#8220;X&#8221;;	// highest value of $i =  217845<br />
$var[] = &#8220;X&#8221;;		// highest value of $i =  245070<br />
$var[][] = &#8220;X&#8221;;		// highest value of $i =   84420</p>
<p>While you showed that constants are the slowest, they are, by far, the least resource intensive,</p>
<p>suprising is that arrays are also less resource intensive then normal variables, even though this effect weakens with multi-demensional arrays</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-100516</link>
		<dc:creator>Johan</dc:creator>
		<pubDate>Fri, 26 Feb 2010 12:34:00 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-100516</guid>
		<description>what the..? And here i was thinking of changing a couple of variables to constants (alot of variables used for multi-language-stuff) to speed up the proces, even by a tiny bit... guess i won&#039;t now,

anyhow, great job on this and thnx</description>
		<content:encoded><![CDATA[<p>what the..? And here i was thinking of changing a couple of variables to constants (alot of variables used for multi-language-stuff) to speed up the proces, even by a tiny bit&#8230; guess i won&#8217;t now,</p>
<p>anyhow, great job on this and thnx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adriano</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-78516</link>
		<dc:creator>Adriano</dc:creator>
		<pubDate>Fri, 10 Oct 2008 11:12:39 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-78516</guid>
		<description>unbelievable!!!

so? should we use variables?</description>
		<content:encoded><![CDATA[<p>unbelievable!!!</p>
<p>so? should we use variables?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PHP Sidor &#187; Blog Archive &#187; Snabbast i PHP - variabler eller konstanter</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-37700</link>
		<dc:creator>PHP Sidor &#187; Blog Archive &#187; Snabbast i PHP - variabler eller konstanter</dc:creator>
		<pubDate>Sun, 12 Aug 2007 19:22:21 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-37700</guid>
		<description>[...] Ã¤r egentligen snabbast, Ã¤r det nÃ¥gon stÃ¶rra skillnad? Jag sÃ¥g en bloggpost om detta, men kom fram till att jag ska fortsÃ¤tta med arrayer eftersom det inte verkar vara nÃ¥gon stÃ¶rre [...]</description>
		<content:encoded><![CDATA[<p>[...] Ã¤r egentligen snabbast, Ã¤r det nÃ¥gon stÃ¶rra skillnad? Jag sÃ¥g en bloggpost om detta, men kom fram till att jag ska fortsÃ¤tta med arrayer eftersom det inte verkar vara nÃ¥gon stÃ¶rre [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lf</title>
		<link>http://planetozh.com/blog/2006/06/php-variables-vs-constants/comment-page-1/#comment-20415</link>
		<dc:creator>lf</dc:creator>
		<pubDate>Tue, 06 Jun 2006 21:57:50 +0000</pubDate>
		<guid isPermaLink="false">http://frenchfragfactory.net/ozh/archives/2006/06/01/php-variables-vs-constants/#comment-20415</guid>
		<description>j&#039;aime bien ton blog, y a pleins de trucs ou je comprends rien, et en plus c&#039;est en anglais, alors Ã§a me rassure.</description>
		<content:encoded><![CDATA[<p>j&#8217;aime bien ton blog, y a pleins de trucs ou je comprends rien, et en plus c&#8217;est en anglais, alors Ã§a me rassure.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

