麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
session传递对象进出现的问题!!
悬赏分:20 - 2007年08月17日

<? 直接生成一个新类: $car = new cart(11); echo is_object($car); //Object 正确! ---------------------------------------------------------- $cart = new cart(20); 通过SESSION传递后,在另一个页面里: echo $cart."
"; print_r($cart)."
"; echo is_object($cart)."
"; -输出:: Object __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => cart [cartid] => 20 [cartpro] => Array ( [5] => 1 ) ) ""//判断返回值为空 这里有问题[/COLOR] 现在想不明白的就是为什么用SESSION传过来的对象好像不是对象 的类型了,出错信息是: ---- Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition cart of the object you are trying to operate on was loaded _before_ the session was started in showcart.php on line 32 ---- 对比了一下,发现出SESSION传递过来的对象中加上了“[__PHP_Incomplete_Class_Name]”,是干什么的呢? 这是我的类文件,大家方便的帮帮看看了! 真的想不出是什么错,类里面的东西好像也是对着的,结构好像也是想要的,到底是怎么了呢!? ?> [PHP] <?php /* //购物车类 //购物车ID,商品信息CARTPRO //CARTPRO结构:一维数组 //CARTPRO([商品ID]=>商品数量,[商品ID]=>商品数量,...) //时间:4.22/05 */ class cart { var $cartid; var $cartpro; //////////////////////////////////////////////////////构造函数,参数USERID,用户的SESSION号 function cart($userid) { if(!empty($userid)) { $this->cartid = $userid; $this->cartpro= array(); } else { $this->error(0); exit(); } } ////////////////////////////////////////////////////////增加商品,参数PROID,商品的ID function additem($proid) { if(array_key_exists($proid, $this->cartpro)) { $this->cartpro[$proid]++; } else { $this->cartpro[$proid]=1; } //$this->error(2); } ///////////////////////////////////////////////////////减少商品,参数PROID,商品ID,一次只减一个,如果没有,删除该ID function removeitem($proid) { if(array_key_exists($proid, $this->cartpro) == true) { if($this->cartpro[$proid]>1) $this->cartpro[$proid]--; else { unset($this->cartpro[$proid]); } } else { $this->error(1); } } ////////////////////////////////////////////////////////删除商品,一次删除一个索引 function delitem($proid) { if(array_key_exists($proid, $this->cartpro)) { unset($this->cartpro[$proid]); } else { $this->error(1); } } //////////////////////////////////////////////////////显示购物车的内容 function showcart() { foreach ($this->cartpro as $key => $value) print "$key*$value|\n"; } function datestr() { $date = ""; foreach($this->cartpro as $key => $value) $date.="$key*$value|"; return $date; } ////////////////////////////////////////////////////////出错提示,参数ERROR! function error($error) { switch ($error) { case 0: echo "<script language='javascript'>alert('你还没有登录,请先登录!');history.go(-1);</script>";exit(); break; case 1: echo "<script language='javascript'>alert('你没有该商品了!');history.go(-1);</script>";exit(); break; case 2: echo "<script language='javascript'>alert('购物成功,请返回继续购物!');window.location='".$_SERVER['HTTP_REFERER']."';</script>";exit(); break; default: echo "<script language='javascript'>alert('程序出错,返回重试!');</script>";exit(); } } } ?> [/PHP]

提问者:smoon   08-17 15:03
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
17 + 79 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM