<?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 Session的一个警告</title>
	<atom:link href="http://www.laruence.com/2009/07/13/976.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.laruence.com/2009/07/13/976.html</link>
	<description>PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 - 左手代码 右手诗</description>
	<lastBuildDate>Thu, 09 Feb 2012 12:31:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: TottyAndBaty</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-2152</link>
		<dc:creator>TottyAndBaty</dc:creator>
		<pubDate>Wed, 19 Aug 2009 07:31:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-2152</guid>
		<description>感谢站长的回答,这是我的那个源文件，代码在php5下测试没有问题，在 php4 下报错，第二个问题也是出在这里

&lt;?php
session_start();
class cart
{
	function cart()
	{
		if(!isset($_SESSION[&quot;cart&quot;]))
		{
			$_SESSION[&quot;cart&quot;]=array();
		}
	}
	//测试用
	function printcart()
	{
		echo &quot;&quot;;
		print_r($_SESSION[&quot;cart&quot;]);
		echo &quot;&quot;;
	}
	//清空购物车
	function clearcart()
	{
		unset($_SESSION[&quot;cart&quot;]);
	}
	//检查指定ID的商品是否存在
	function iscart($cartid)
	{
		$iscart[&quot;action&quot;]=false;
		foreach($_SESSION[&quot;cart&quot;] as $key=&gt;$value)
		{
			if($value[&quot;id&quot;]==$cartid)
			{
				$iscart[&quot;action&quot;]=true;
				$iscart[&quot;key&quot;]=$key;
			}
		}
		return $iscart;
	}
	//购买，依次传入ID,数量，价格，单位，名称
	function addcart($cartid,$count,$price,$danwei,$name)
	{
		$iscart=$this-&gt;iscart($cartid);
		if($iscart[&quot;action&quot;])
		{
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;]+=$count;
			$c=  $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;];
			$price= $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;price&quot;];
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;total&quot;]=$c*$price;
		}
		else
		{
			$total=$count*$price;
			$_SESSION[&quot;cart&quot;][]=array(&quot;id&quot;=&gt;$cartid,
			&quot;count&quot;=&gt;$count,
			&quot;price&quot;=&gt;$price,
			&quot;total&quot;=&gt;$total,
			&quot;danwei&quot;=&gt;$danwei,
			&quot;name&quot;=&gt;$name
			);
		}
	}
	//重复购买，默认一次为1个
	function addMore($cartid,$count=1)
	{
		$iscart=$this-&gt;iscart($cartid);
		if($iscart[&quot;action&quot;])
		{
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;]+=$count;
			$c=  $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;];
			$price= $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;price&quot;];
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;total&quot;]=$c*$price;
		}
	}
	//减少数量，默认为1
	function moveout($cartid)
	{
		//删除某件商品
		$iscart=$this-&gt;iscart($cartid);
		unset($_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]]);
	}
	//删除某件商品
	function delcart($cartid,$count)
	{
		//修改件数
		$iscart=$this-&gt;iscart($cartid);
		if($iscart[&quot;action&quot;])
		{
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;]-=$count;
			$c=  $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;];
			$price= $_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;price&quot;];
			$_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;total&quot;]=$c*$price;
			if($_SESSION[&quot;cart&quot;][$iscart[&quot;key&quot;]][&quot;count&quot;]</description>
		<content:encoded><![CDATA[<p>感谢站长的回答,这是我的那个源文件，代码在php5下测试没有问题，在 php4 下报错，第二个问题也是出在这里</p>
<p>&lt;?php<br />
session_start();<br />
class cart<br />
{<br />
	function cart()<br />
	{<br />
		if(!isset($_SESSION["cart"]))<br />
		{<br />
			$_SESSION["cart"]=array();<br />
		}<br />
	}<br />
	//测试用<br />
	function printcart()<br />
	{<br />
		echo &#8220;&#8221;;<br />
		print_r($_SESSION["cart"]);<br />
		echo &#8220;&#8221;;<br />
	}<br />
	//清空购物车<br />
	function clearcart()<br />
	{<br />
		unset($_SESSION["cart"]);<br />
	}<br />
	//检查指定ID的商品是否存在<br />
	function iscart($cartid)<br />
	{<br />
		$iscart["action"]=false;<br />
		foreach($_SESSION["cart"] as $key=&gt;$value)<br />
		{<br />
			if($value["id"]==$cartid)<br />
			{<br />
				$iscart["action"]=true;<br />
				$iscart["key"]=$key;<br />
			}<br />
		}<br />
		return $iscart;<br />
	}<br />
	//购买，依次传入ID,数量，价格，单位，名称<br />
	function addcart($cartid,$count,$price,$danwei,$name)<br />
	{<br />
		$iscart=$this-&gt;iscart($cartid);<br />
		if($iscart["action"])<br />
		{<br />
			$_SESSION["cart"][$iscart["key"]]["count"]+=$count;<br />
			$c=  $_SESSION["cart"][$iscart["key"]]["count"];<br />
			$price= $_SESSION["cart"][$iscart["key"]]["price"];<br />
			$_SESSION["cart"][$iscart["key"]]["total"]=$c*$price;<br />
		}<br />
		else<br />
		{<br />
			$total=$count*$price;<br />
			$_SESSION["cart"][]=array(&#8220;id&#8221;=&gt;$cartid,<br />
			&#8220;count&#8221;=&gt;$count,<br />
			&#8220;price&#8221;=&gt;$price,<br />
			&#8220;total&#8221;=&gt;$total,<br />
			&#8220;danwei&#8221;=&gt;$danwei,<br />
			&#8220;name&#8221;=&gt;$name<br />
			);<br />
		}<br />
	}<br />
	//重复购买，默认一次为1个<br />
	function addMore($cartid,$count=1)<br />
	{<br />
		$iscart=$this-&gt;iscart($cartid);<br />
		if($iscart["action"])<br />
		{<br />
			$_SESSION["cart"][$iscart["key"]]["count"]+=$count;<br />
			$c=  $_SESSION["cart"][$iscart["key"]]["count"];<br />
			$price= $_SESSION["cart"][$iscart["key"]]["price"];<br />
			$_SESSION["cart"][$iscart["key"]]["total"]=$c*$price;<br />
		}<br />
	}<br />
	//减少数量，默认为1<br />
	function moveout($cartid)<br />
	{<br />
		//删除某件商品<br />
		$iscart=$this-&gt;iscart($cartid);<br />
		unset($_SESSION["cart"][$iscart["key"]]);<br />
	}<br />
	//删除某件商品<br />
	function delcart($cartid,$count)<br />
	{<br />
		//修改件数<br />
		$iscart=$this-&gt;iscart($cartid);<br />
		if($iscart["action"])<br />
		{<br />
			$_SESSION["cart"][$iscart["key"]]["count"]-=$count;<br />
			$c=  $_SESSION["cart"][$iscart["key"]]["count"];<br />
			$price= $_SESSION["cart"][$iscart["key"]]["price"];<br />
			$_SESSION["cart"][$iscart["key"]]["total"]=$c*$price;<br />
			if($_SESSION["cart"][$iscart["key"]]["count"]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 雪候鸟</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-2134</link>
		<dc:creator>雪候鸟</dc:creator>
		<pubDate>Fri, 14 Aug 2009 09:50:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-2134</guid>
		<description>@TottyAndBaty 第一个问题, 你是否在PHP5中使用了auto_load机制? 
Session在反序列化你的对象的时候, 如果找不到对象的类定义, 那么这个对象的类型就会是_PHP_Incomplete_Class Object,

解决方法是在,session_start之前, 载入你的类定义.

至于,第二个问题, 我没遇到过, 你能给个重现代码么?</description>
		<content:encoded><![CDATA[<p>@TottyAndBaty 第一个问题, 你是否在PHP5中使用了auto_load机制?<br />
Session在反序列化你的对象的时候, 如果找不到对象的类定义, 那么这个对象的类型就会是_PHP_Incomplete_Class Object,</p>
<p>解决方法是在,session_start之前, 载入你的类定义.</p>
<p>至于,第二个问题, 我没遇到过, 你能给个重现代码么?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TottyAndBaty</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-2133</link>
		<dc:creator>TottyAndBaty</dc:creator>
		<pubDate>Fri, 14 Aug 2009 07:50:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-2133</guid>
		<description>文章很精彩！看到你写的这篇文章，我想起了我之前使用session做的一个购物车，

服务器的register_globals=off,我的购物车本身的类名叫cart,而我的购物车保存在$_SESSION[&quot;cart&quot;]中，在php5 下运行可以，但是php4下却报错了，系统提示：__PHP_Incomplete_Class Object，当然我把类名改一下或者改一下$_SESSION问题就可以解决，不知道为什么。

这个问题解决了，但是后来又出现问题，我使用了一个 $_SESSION[&quot;count&quot;],这个也报错了，好像把这里的count理解为函数了，博主是否帮忙解释一下？谢谢</description>
		<content:encoded><![CDATA[<p>文章很精彩！看到你写的这篇文章，我想起了我之前使用session做的一个购物车，</p>
<p>服务器的register_globals=off,我的购物车本身的类名叫cart,而我的购物车保存在$_SESSION["cart"]中，在php5 下运行可以，但是php4下却报错了，系统提示：__PHP_Incomplete_Class Object，当然我把类名改一下或者改一下$_SESSION问题就可以解决，不知道为什么。</p>
<p>这个问题解决了，但是后来又出现问题，我使用了一个 $_SESSION["count"],这个也报错了，好像把这里的count理解为函数了，博主是否帮忙解释一下？谢谢</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: panjinww</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1860</link>
		<dc:creator>panjinww</dc:creator>
		<pubDate>Tue, 14 Jul 2009 14:00:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1860</guid>
		<description>学习了，貌似咱少的就是这种钻研的精神！</description>
		<content:encoded><![CDATA[<p>学习了，貌似咱少的就是这种钻研的精神！</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sky</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1857</link>
		<dc:creator>sky</dc:creator>
		<pubDate>Tue, 14 Jul 2009 10:21:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1857</guid>
		<description>这种多见于兼容php4脚本的情况</description>
		<content:encoded><![CDATA[<p>这种多见于兼容php4脚本的情况</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 雪候鸟</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1855</link>
		<dc:creator>雪候鸟</dc:creator>
		<pubDate>Tue, 14 Jul 2009 02:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1855</guid>
		<description>你的文采真好, 夸的我开心的~ 嘿嘿</description>
		<content:encoded><![CDATA[<p>你的文采真好, 夸的我开心的~ 嘿嘿</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: keyvalue</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1853</link>
		<dc:creator>keyvalue</dc:creator>
		<pubDate>Tue, 14 Jul 2009 01:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1853</guid>
		<description>好文，知其所以然的路很艰难，你却如履平地。。。</description>
		<content:encoded><![CDATA[<p>好文，知其所以然的路很艰难，你却如履平地。。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 雪候鸟</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1849</link>
		<dc:creator>雪候鸟</dc:creator>
		<pubDate>Mon, 13 Jul 2009 09:53:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1849</guid>
		<description>说的好~ 呵呵</description>
		<content:encoded><![CDATA[<p>说的好~ 呵呵</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xi2008wang</title>
		<link>http://www.laruence.com/2009/07/13/976.html/comment-page-1#comment-1848</link>
		<dc:creator>xi2008wang</dc:creator>
		<pubDate>Mon, 13 Jul 2009 08:41:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.laruence.com/?p=976#comment-1848</guid>
		<description>在源代码面前没有密码.</description>
		<content:encoded><![CDATA[<p>在源代码面前没有密码.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

