<?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>Compiled Thoughts by John Ciacia &#187; empty</title>
	<atom:link href="http://www.johnciacia.com/tag/empty/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johnciacia.com</link>
	<description>Science, Technology, and Beyond</description>
	<lastBuildDate>Fri, 06 Jan 2012 15:46:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>isset vs. empty</title>
		<link>http://www.johnciacia.com/2010/01/09/isset-vs-empty/</link>
		<comments>http://www.johnciacia.com/2010/01/09/isset-vs-empty/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 04:32:48 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[empty]]></category>
		<category><![CDATA[isset]]></category>

		<guid isPermaLink="false">http://www.johnciacia.com/?p=466</guid>
		<description><![CDATA[Many people tend to view these two functions as opposites, causing necessary debugging. This issue frequently occurs when validating forms. isset() From the PHP manual: isset — Determine if a variable is set and is not NULL In other words, a variable is set if it has been assigned a value other than NULL. If [...]]]></description>
			<content:encoded><![CDATA[<p>Many people tend to view these two functions as opposites, causing necessary debugging. This issue frequently occurs when validating forms.</p>
<h2>isset()</h2>
<p>From the PHP manual:</p>
<blockquote><p>isset — Determine if a variable is set and is not NULL</p></blockquote>
<p>In other words, a variable <strong>is set</strong> if it has been assigned a value other than NULL. If a variable is assigned to be an empty string &#8211; it is set. The following code and output should illustrate my point.<br />
[code lang="PHP"]<?php</p>
<p>var_dump(isset($x));</p>
<p>$x = NULL;<br />
var_dump(isset($x));</p>
<p>$x = "";<br />
var_dump(isset($x));</p>
<p>$x = '';<br />
var_dump(isset($x));</p>
<p>?>[/code]</p>
<div class="quote">bool(false)<br />
bool(false)<br />
bool(true)<br />
bool(true)
</div>
<h2>empty()</h2>
<p>Again from the PHP manual:</p>
<blockquote><p>empty — Determine whether a variable is empty</p></blockquote>
<p>In other words, a variable is <strong>empty</strong> if it is an empty string, 0, &#8220;0&#8243;, false, NULL, array(), and an unset variable are all empty.</p>
<p>[code lang="PHP"]<?php</p>
<p>var_dump(empty($x));</p>
<p>$x = NULL;<br />
var_dump(empty($x));</p>
<p>$x = "";<br />
var_dump(empty($x));</p>
<p>$x = '';<br />
var_dump(empty($x));</p>
<p>$x = "0";<br />
var_dump(empty($x));</p>
<p>$x = 0;<br />
var_dump(empty($x));</p>
<p>$x = false;<br />
var_dump(empty($x));</p>
<p>$x = array();<br />
var_dump(empty($x));</p>
<p>?>[/code]</p>
<div class="quote">bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)<br />
bool(true)
</div>
<p>Now when you are validating forms to make sure a user did not leave a form field blank, it is probably best to use neither empty() or isset() (not that isset would work). Since it is possible your form might accept 0 as a valid answer. Therefore you should just check to make sure it is not an empty string.</p>
<p>[code lang="PHP"]<?php<br />
if($_GET['foo'] == "") {<br />
    echo "You must enter a value for foo!";<br />
}<br />
?>[/code]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johnciacia.com/2010/01/09/isset-vs-empty/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.johnciacia.com @ 2012-02-05 10:40:51 -->
