<?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: Conditional text despite content not being echoed</title>
	<atom:link href="http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 23:07:01 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: aeon</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13733</link>
		<dc:creator>aeon</dc:creator>
		<pubDate>Fri, 24 Dec 2004 00:30:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13733</guid>
		<description>erk. didn&#039;t escape the tags... sorry. Meant this:
&lt;?php
$nextpost = next_post();
if(!empty($nextpost))
{
&#160;&#160;&#160;&#160;next_post(&#039;&#171; % &#124; &#039;,&#039;previous&#039;,&#039;no&#039;);
}
else
{
&#160;&#160;&#160;&#160;echo &#039;&lt;span class=&quot;grey&quot;&gt;&#171; previous&lt;/span&gt; &#124; &#039;;
}
?&gt;</description>
		<content:encoded><![CDATA[<p>erk. didn&#039;t escape the tags&#8230; sorry. Meant this:<br />
&lt;?php<br />
$nextpost = next_post();<br />
if(!empty($nextpost))<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;next_post(&#039;&laquo; % | &#039;,&#039;previous&#039;,'no&#039;);<br />
}<br />
else<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;echo &#039;&lt;span class=&#034;grey&#034;&gt;&laquo; previous&lt;/span&gt; | &#039;;<br />
}<br />
?&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aeon</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13732</link>
		<dc:creator>aeon</dc:creator>
		<pubDate>Fri, 24 Dec 2004 00:27:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13732</guid>
		<description>Hm. I am not really sure what your next_post function returns - if I were to write it, it would return a boolean value when called without arguments. But why not just do this:
&lt; ?php
$nextpost = next_post();
if(!empty($nextpost))
{
    next_post(&#039;&#171; % &#124; &#039;,&#039;previous&#039;,&#039;no&#039;);
} else { ?&gt;
&lt;span class=&quot;grey&quot;&gt;&#171; previous&lt;/span&gt; &#124;
&lt; ?php } ?&gt;</description>
		<content:encoded><![CDATA[<p>Hm. I am not really sure what your next_post function returns &#8211; if I were to write it, it would return a boolean value when called without arguments. But why not just do this:<br />
< ?php<br />
$nextpost = next_post();<br />
if(!empty($nextpost))<br />
{<br />
    next_post('&laquo; % | ','previous','no');<br />
} else { ?><br />
<span class="grey">&laquo; previous</span> |<br />
< ?php } ?></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: branson</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13502</link>
		<dc:creator>branson</dc:creator>
		<pubDate>Sat, 04 Dec 2004 01:20:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13502</guid>
		<description>I&#039;ve never use the output buffering, just stick to templates for the sake of maintainability. Just installed Wordpress and am looking forward to customizing.  Glad I found your site!</description>
		<content:encoded><![CDATA[<p>I&#039;ve never use the output buffering, just stick to templates for the sake of maintainability. Just installed WordPress and am looking forward to customizing.  Glad I found your site!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13360</link>
		<dc:creator>Marcus</dc:creator>
		<pubDate>Wed, 24 Nov 2004 20:20:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13360</guid>
		<description>It&#039;s probably just a personal preference of mine.

It may sound a bit too philosophical, or idealist, but in a way, certain things make me feel like I&#039;m breaking the natural flow of the code. I don&#039;t like any kind of &lt;code&gt;print()&lt;/code&gt; or &lt;code&gt;echo()&lt;/code&gt; statements in functions, anything resembling &lt;code&gt;goto&lt;/code&gt; statements is a big no in my book, I stay away from things such as &lt;code&gt;continue;&lt;/code&gt; and &lt;code&gt;break;&lt;/code&gt; unless it&#039;s in a &lt;code&gt;switch&lt;/code&gt; statement (in the case of &lt;code&gt;break;&lt;/code&gt; anyway). &lt;code&gt;switch&lt;/code&gt; constructs should be kept as short as possible, break them down into functions. I&#039;m an object fanatic and believe that &quot;good code is code that is very readable&quot;(* see footnote) and, thus, maintainable.

For example, I prefer tabs over spaces. They take up less space, and you can set the tab stop in most editors. I have mine set to 4.

My if statements are always formatted like this:
&lt;code&gt;
if (USERID_ROOT == $userid) // check for root user
{
	// display the IP address of the poster
	print(&quot;$ip&quot;);
}
else // not root user:
{
	// display the &quot;report post&quot; link
	print(&quot;$report_url&quot;);
}
&lt;/code&gt;

1. the { and } are mandatory and always lined up in the same column, you would never see me do something like:
&lt;code&gt;
if (condition) {
  echo(&#039;true&#039;);
}
&lt;/code&gt;

2. the USERID_ROOT is a constant. Never use &quot;magic numbers&quot;.

3. I always put the constant on the left side of the equation. If I were to make a typo, &lt;code&gt;if ($userid = USERID_ROOT)&lt;/code&gt; would always evaluate as true, but &lt;code&gt;if (USERID_ROOT = $userid)&lt;/code&gt; will cause an error message. (I picked this one up not too long ago, and it took me a while to get used to it)

4. I try to comment a lot. I don&#039;t think I&#039;m necessarily overcommenting, but do I try to comment in a way so you could remove all code and just by reading the comments you can still understand the flow of the application.


I&#039;m also a HUGE fan of using templates. Whether it&#039;s &lt;a href=&quot;http://pear.php.net/package/HTML_Template_Sigma&quot;&gt;Sigma&lt;/a&gt; (my second favorite), &lt;a href=&quot;http://smarty.php.net/&quot;&gt;Smarty&lt;/a&gt; (looked into it, found it too convoluted) or my home-grown, which I primarily use. &lt;a href=&quot;http://www.massassi.com/php/articles/template_engines/&quot;&gt;Here is a good read&lt;/a&gt; on the topic.

Back to the original issue: I&#039;ve used the output buffering trick once. I used the auto_prepend_file and auto_append_file php.ini settings to re-brand an existing web site for a company this investment firm had just bought. The problem was that the company and product names appeared all over the place. Hardcoded in PHP, and all throughout the database. So I used output buffering and did a simple &lt;code&gt;str_replace()&lt;/code&gt; on the buffer. But to use that on a simple function just seems overkill to me.

I don&#039;t think there are any complications that could occur other than readability suffering a bit, perhaps.

Hmm. I realize that this comment has turned into a huge rant with little nutritional value, and not only that -- it sounds like I like it &quot;my way or the highway&quot;, but I&#039;ll post it anyway. :)

------

* When I started to program more seriously (in the 386 era) &quot;good code&quot; was still a lot about hand-optimizing assembly statements for time-critial portions of C or Turbo Pascal code. Granted, that was for a different market (software and in particular game development). Unrolling loops, using &lt;code&gt;XOR AX,AX&lt;/code&gt; instead of &lt;code&gt;MOV AX,0&lt;/code&gt;, avoiding &lt;code&gt;CMP&lt;/code&gt; statements. In web development it&#039;s all about maintainability. It&#039;s far more cost-efficient to just create a web server farm than it is to spend additional $ on re-design, code cleanup, and slowly working new features into spaghetti code and convoluting the existing code ever so more.</description>
		<content:encoded><![CDATA[<p>It&#039;s probably just a personal preference of mine.</p>
<p>It may sound a bit too philosophical, or idealist, but in a way, certain things make me feel like I&#039;m breaking the natural flow of the code. I don&#039;t like any kind of <code>print()</code> or <code>echo()</code> statements in functions, anything resembling <code>goto</code> statements is a big no in my book, I stay away from things such as <code>continue;</code> and <code>break;</code> unless it&#039;s in a <code>switch</code> statement (in the case of <code>break;</code> anyway). <code>switch</code> constructs should be kept as short as possible, break them down into functions. I&#039;m an object fanatic and believe that &#034;good code is code that is very readable&#034;(* see footnote) and, thus, maintainable.</p>
<p>For example, I prefer tabs over spaces. They take up less space, and you can set the tab stop in most editors. I have mine set to 4.</p>
<p>My if statements are always formatted like this:<br />
<code><br />
if (USERID_ROOT == $userid) // check for root user<br />
{<br />
	// display the IP address of the poster<br />
	print("$ip");<br />
}<br />
else // not root user:<br />
{<br />
	// display the "report post" link<br />
	print("$report_url");<br />
}<br />
</code></p>
<p>1. the { and } are mandatory and always lined up in the same column, you would never see me do something like:<br />
<code><br />
if (condition) {<br />
  echo('true');<br />
}<br />
</code></p>
<p>2. the USERID_ROOT is a constant. Never use &#034;magic numbers&#034;.</p>
<p>3. I always put the constant on the left side of the equation. If I were to make a typo, <code>if ($userid = USERID_ROOT)</code> would always evaluate as true, but <code>if (USERID_ROOT = $userid)</code> will cause an error message. (I picked this one up not too long ago, and it took me a while to get used to it)</p>
<p>4. I try to comment a lot. I don&#039;t think I&#039;m necessarily overcommenting, but do I try to comment in a way so you could remove all code and just by reading the comments you can still understand the flow of the application.</p>
<p>I&#039;m also a HUGE fan of using templates. Whether it&#039;s <a href="http://pear.php.net/package/HTML_Template_Sigma">Sigma</a> (my second favorite), <a href="http://smarty.php.net/">Smarty</a> (looked into it, found it too convoluted) or my home-grown, which I primarily use. <a href="http://www.massassi.com/php/articles/template_engines/">Here is a good read</a> on the topic.</p>
<p>Back to the original issue: I&#039;ve used the output buffering trick once. I used the auto_prepend_file and auto_append_file php.ini settings to re-brand an existing web site for a company this investment firm had just bought. The problem was that the company and product names appeared all over the place. Hardcoded in PHP, and all throughout the database. So I used output buffering and did a simple <code>str_replace()</code> on the buffer. But to use that on a simple function just seems overkill to me.</p>
<p>I don&#039;t think there are any complications that could occur other than readability suffering a bit, perhaps.</p>
<p>Hmm. I realize that this comment has turned into a huge rant with little nutritional value, and not only that &#8212; it sounds like I like it &#034;my way or the highway&#034;, but I&#039;ll post it anyway. <img src='http://www.scriptygoddess.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8212;&#8212;</p>
<p>* When I started to program more seriously (in the 386 era) &#034;good code&#034; was still a lot about hand-optimizing assembly statements for time-critial portions of C or Turbo Pascal code. Granted, that was for a different market (software and in particular game development). Unrolling loops, using <code>XOR AX,AX</code> instead of <code>MOV AX,0</code>, avoiding <code>CMP</code> statements. In web development it&#039;s all about maintainability. It&#039;s far more cost-efficient to just create a web server farm than it is to spend additional $ on re-design, code cleanup, and slowly working new features into spaghetti code and convoluting the existing code ever so more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jennifer</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13359</link>
		<dc:creator>Jennifer</dc:creator>
		<pubDate>Wed, 24 Nov 2004 18:39:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13359</guid>
		<description>I guess I was trying to avoid hacking the core code, or creating duplicate functions just so they didn&#039;t echo the text.

Just curious - why do you consider output buffering a last resort. What complications can occur by using it?</description>
		<content:encoded><![CDATA[<p>I guess I was trying to avoid hacking the core code, or creating duplicate functions just so they didn&#039;t echo the text.</p>
<p>Just curious &#8211; why do you consider output buffering a last resort. What complications can occur by using it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus</title>
		<link>http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/comment-page-1/#comment-13358</link>
		<dc:creator>Marcus</dc:creator>
		<pubDate>Wed, 24 Nov 2004 18:09:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.scriptygoddess.com/archives/2004/11/22/conditional-text-despite-content-not-being-echoed/#comment-13358</guid>
		<description>Honestly, I&#039;ve always found the output buffering method to be a last resort. But it also bugs me to no end that so many of the WP functions just print things out instead of returning them.

Ideally, why not modify the next_post() function to either return a link, or grayed out text. Seems cleaner to me.</description>
		<content:encoded><![CDATA[<p>Honestly, I&#039;ve always found the output buffering method to be a last resort. But it also bugs me to no end that so many of the WP functions just print things out instead of returning them.</p>
<p>Ideally, why not modify the next_post() function to either return a link, or grayed out text. Seems cleaner to me.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.999 seconds -->
