<?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>Chintoju's blog &#187; php</title>
	<atom:link href="http://blog.chintoju.com/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chintoju.com</link>
	<description>Can you get something out of nothing...</description>
	<lastBuildDate>Thu, 08 Oct 2009 02:07:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A particular session variable&#8217;s value disappearing from $_SESSION in PHP</title>
		<link>http://blog.chintoju.com/2008/07/a-particular-session-variables-value-disappearing-from-_session-in-php.html</link>
		<comments>http://blog.chintoju.com/2008/07/a-particular-session-variables-value-disappearing-from-_session-in-php.html#comments</comments>
		<pubDate>Sun, 13 Jul 2008 14:03:00 +0000</pubDate>
		<dc:creator>Kishore</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://blog.chintoju.com/?p=23</guid>
		<description><![CDATA[A particular session variable&#8217;s value disappearing from $_SESSION in PHP&#8230; ??
Just check to make sure you DON&#8217;T have register_globals turned On. This took me a few hour&#8217;s to figure out..
Example scenario..
Form Bean class

class FormBean
{
public $email;
public $name;
}

page1.php

$form = new FormBean();
$form-&#62;email = "someone@something.com.au";
$_SESSION['form'] = serialize($form);
header("location:page2.php");

page2.php

$form =NULL;
if(isset($_SESSION['form']))
{
$form = unserialize($_SESSION['form']);
}
echo $form-&#62;email;

Expected to print &#8220;someone@something.com.au&#8221; right. Usually it does. If [...]]]></description>
			<content:encoded><![CDATA[<p>A particular session variable&#8217;s value disappearing from $_SESSION in PHP&#8230; ??</p>
<p>Just check to make sure you DON&#8217;T have <span style="font-weight: bold;">register_globals</span> turned <span style="font-weight: bold;">On.</span> This took me a few hour&#8217;s to figure out..</p>
<p>Example scenario..<br />
<span style="text-decoration: underline;">Form Bean class</span><br />
<code><br />
class FormBean<br />
{<br />
public $email;<br />
public $name;<br />
}<br />
</code></p>
<p><span style="text-decoration: underline;">page1.php</span><br />
<code><br />
$form = new FormBean();<br />
$form-&gt;email = "someone@something.com.au";<br />
$_SESSION['form'] = serialize($form);<br />
header("location:page2.php");<br />
</code></p>
<p><span style="text-decoration: underline;">page2.php</span><br />
<code><br />
$form =NULL;<br />
if(isset($_SESSION['form']))<br />
{<br />
$form = unserialize($_SESSION['form']);<br />
}<br />
echo $form-&gt;email;<br />
</code></p>
<p>Expected to print &#8220;someone@something.com.au&#8221; right. Usually it does. If it doesn&#8217;t and you see that all other session variables are intact except &#8216;form&#8217;, then it&#8217;s time to look at your &#8216;register_globals&#8217; setting. One of my client uses this pretty lax hosting which had this on what it has done is &#8230;.</p>
<p><span style="text-decoration: underline;">page2.php</span><br />
<code><br />
<strong>$form =NULL;</strong> <span style="color: #f67c2a;">//This sets the form bean to NULL.. wherever it is stored. Throughout the entire website. (Even IN $_SESSION)</span></code></p>
<p><code> </code></p>
<p><code>if(isset($_SESSION['form']))<br />
{<br />
$form = unserialize($_SESSION['form']);<br />
}<br />
echo $form-&gt;email;<br />
</code></p>
<p>So the <span id="SPELLING_ERROR_0" class="blsp-spelling-error">lesson</span> learnt for me was&#8230; Just check to make sure <span style="font-weight: bold;">register_<span id="SPELLING_ERROR_1" class="blsp-spelling-error"><span id="SPELLING_ERROR_0" class="blsp-spelling-error">globals</span></span></span> is <span style="font-weight: bold;">Off</span> whenever you switch to new hosting.. <span id="SPELLING_ERROR_2" class="blsp-spelling-error"><span id="SPELLING_ERROR_1" class="blsp-spelling-error">coz</span></span> that is pure EVIL.</p>
<p>How you can turn it off.. There are two different ways.</p>
<ol>
<li><span style="font-weight: bold;"><a href="http://www.php.net/ini_set"><span id="SPELLING_ERROR_3" class="blsp-spelling-error"><span id="SPELLING_ERROR_2" class="blsp-spelling-error">ini</span></span>_set</a><br />
</span></li>
<li><span style="font-weight: bold;">.<a href="http://www.askapache.com/php/custom-phpini-tips-and-tricks.html"><span id="SPELLING_ERROR_4" class="blsp-spelling-error"><span id="SPELLING_ERROR_3" class="blsp-spelling-error">htaccess</span></span></a></span></li>
</ol>
<p>This also makes me feel that PHP&#8217;s OOP implementation is either misleading , buggy or at least fundamentally different to other OOP languages like Java or C#.</p>
<p>Consider this in Java:<br />
<span style="text-decoration: underline;">FormBean.java</span><br />
<code><br />
class FormBean<br />
{<br />
public String email;<br />
}<br />
</code></p>
<p><span style="text-decoration: underline;">TestFormBean.java</span><br />
<code><br />
class TestFormBean<br />
{<br />
public static void main(String[] args)<br />
{<br />
FormBean form1 = new FormBean(); <span style="color:#F67C2A">//Create new form bean</span><br />
form1.email = "someone@something.com.au"; <span style="color:#F67C2A">//populate form bean</span></code></p>
<p><code>FormBean form2 = form1; <span style="color:#F67C2A">//Assign created form bean object to another reference variable</span><br />
form1 = null;</p>
<p></code></p>
<p><code> System.out.println(form2.email);<br />
<span style="color:#F67C2A"><br />
//would still print "someone@something.com.au"<br />
//i.e. Just setting one reference to NULL won't kill its object instance.</span><br />
}<br />
}</code><br />
I have tested similar code with PHP though&#8230; I have only realised <strong>register_globals</strong> seems to affect the ways objects and their references are handled. Like setting one reference of an object to NULL killing the object instance, which essentially renders all my other references useless.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chintoju.com/2008/07/a-particular-session-variables-value-disappearing-from-_session-in-php.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
