<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Boolean Flags &#8211; Programming blog &#8211; website programming blog, blog on website programming .net, java , php and mor</title>
	<atom:link href="https://www.searchenginegenie.com/programming-blog/tag/boolean-flags/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.searchenginegenie.com/programming-blog</link>
	<description></description>
	<lastBuildDate>Tue, 11 Dec 2012 08:56:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.5</generator>
	<item>
		<title>How to handle errors using Boolean flags</title>
		<link>https://www.searchenginegenie.com/programming-blog/how-to-handle-errors-using-boolean-flags/</link>
					<comments>https://www.searchenginegenie.com/programming-blog/how-to-handle-errors-using-boolean-flags/#respond</comments>
		
		<dc:creator><![CDATA[Camilla]]></dc:creator>
		<pubDate>Thu, 16 Oct 2008 13:41:00 +0000</pubDate>
				<category><![CDATA[Programmer]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Troubleshoot]]></category>
		<category><![CDATA[Boolean Flags]]></category>
		<category><![CDATA[Error hangling method]]></category>
		<guid isPermaLink="false">http://www.searchenginegenie.com/programming-blog/how-to-handle-errors-using-boolean-flags/</guid>

					<description><![CDATA[This error handling method may be the most ancient. Boolean flags were used by many programming languages, and PHP will not be an exception. Even though they are very simple to apply, the main negative aspect is that they were not very informative about the mistake that happened and its perspective. Here is an unsophisticated [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>This error handling method may be the most ancient. Boolean flags were used by many programming languages, and PHP will not be an exception. Even though they are very simple to apply, the main negative aspect is that they were not very informative about the mistake that happened and its perspective. Here is an unsophisticated implementation of the FileReader class, which make use of Boolean flags:</p>
<p>[php]<br />
class FileReader{<br />
 var $file;<br />
 var $fileDir=&#8217;fileDir/&#8217;;<br />
 function FileReader($file){<br />
 if(!@file_exists(&quot;{$this-&gt;fileDir}{$file}.php&quot;)){<br />
 return false;<br />
 }<br />
 $this-&gt;file=$file;<br />
 }<br />
 function getContent(){<br />
 if(!@$content=file_get_contents(&quot;{$this-&gt;fileDir}{$this-&gt;file}.php&quot;)){<br />
 return false;<br />
 }<br />
 return $content;<br />
 }<br />
 }<br />
[/php]</p>
<p>Bearing in mind about the explanation for the above example, class errors might be handled as follows:</p>
<p>[php]<br />
$fr=new FileReader(&#8216;inexistent_file&#8217;);<br />
 if(!$fr-&gt;getContent()){<br />
 die(&#8216;Unable to read file contents&#8217;);<br />
 }<br />
 else{<br />
 echo $fr-&gt;getContent();<br />
 }<br />
[/php]</p>
<p>In the example, @ error suppression operator is intentionally used, so as to stay away from the complaints of the PHP interpreter and return a false value (or 0 or -1) when a failure happens. At first look, you can observe the incompetence of this method, plus its restricted flexibility. On the other hand, this approach has established to be quite victorious in procedural applications, or when client code is able to handle straightforward errors without corrupting the entire application.</p>
<p>Nowadays, we have investigated the pros and cons of common error handling approaches in PHP 4. Certainly, in huge web applications, a set of error controlling classes is preferred, so you are able to handle errors through a centralized point. Conversely, the trigger_error () / set_error_handler () combination may suit the requirements of small projects, so it is worth considering.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.searchenginegenie.com/programming-blog/how-to-handle-errors-using-boolean-flags/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.searchenginegenie.com @ 2024-11-01 23:10:01 by W3 Total Cache
-->