对象要想通过SESSION传递得先序列化一下才行:
$sobject=serialize($object);

解决方案 »

  1.   

    看不出你的问题哪里有“对象”如果真是要用SESSION传递对象,必须先序列化:
    $str = serialize($object);
    取出后要去序列化:
    $object = unserialize($str);另外,SESSION 只能保存对象的属性,方法会自动丢失
      

  2.   

    没有方法光有属性有什么用呀?
    叫我怎么取到里面的值?
    existence
    Fatal error: 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 D:\Lida\InfoChange.php on line 10
    //上面第一行的是if(isset($Objcart)){echo...}来的。
    //后面是用了$Objcart->GetOwner()来的。请问有什么方法能调用方法呢?
    //如果没有方法,如何取到属性值呢?
      

  3.   

    正确地序列化这后用SESSION或COOKIE传递,再反序列化成对象,属性和方法都不会丢失的,如果不序列化,方法肯定丢失.
      

  4.   

    目前的 PHP 版本,serialize 函数只支持对象的属性,不支持方法,没办法
      

  5.   

    并不见得呀,几位高手。虽然我的问题没有解决,但这几个用来test的文件在我这儿却好用得很呐:
    //<?php
    //session test
    //1.php
    include("user.php");
    session_start();
    $user=new user("fuxiao","realname");
    session_register("user");
    $user->userid="keyizhijie";
    echo '<br>session name is '.session_name();
    session_name("yt");
    echo $user->getid();
    echo "<br>the new session name is ";
    echo session_name();
    echo "<br>session id is ".session_id();echo "<a href='2.php'>2.php</a>";
    ?>
      

  6.   

    <?php
    //2.php
    //session test,the test include those files :1.php,2,php,3,php;
      echo "<a href='3.php'>3.php</a>";
    ?>
      

  7.   

    <?php
    //3.php
    //session test,the test include those files :1.php,2,php,3,php;
    include("user.php");
    session_start();
    if(isset($user))
     {echo "user has already registed";
      echo $user->getid();
      echo session_id();
      echo session_name();
    }
    else
      {
       echo "tnnd,there is no session existence";
    }
    ?>
      

  8.   

    to: alexxing(赤铸)
    你听谁说的呀,谁说PHP目前的版本serialize 函数只支持对象的属性,不支持方法呀?你用的是PHP的哪个版本啊?
    你好好看看电子工业出版社出的<<PHP4宝典>>第427页!!
      

  9.   

    不好意思,不知道一次至多贴三个,另外一个文件就是定义了那个类,有getid方法了.
    <<PHP 4.X与电子商务网站开发实战>>周浩编著   人民邮电出版
    上面有个例子,直接注册对象为session变量.我上面的几个好象可以证明这点,(我的好像是PHP Version 4.2.3).不过,我原来的问题却还没有发现问题所在呀!!
      

  10.   

    哦,我的天,原来是这样的:
    我在session_start()之前包含了一个checklogin.php,这个文件中也有一个session_start(),我现在把它注释掉,就可以了!!
    哎,这两天都吃不下饭呀!!
    这个现象有谁能解释一下呢?为什么不能两次在同一处用session_start()另外,谁说session不支持对象(方法会没有)呀?
    我现在也没有序列化,用得好好的。telescope(望远镜) alexxing(赤铸)谢谢你们了,日后再散分时,不会忘记两位的!
      

  11.   

    to telescope(望远镜): 我的 PHP 手册里就是这么写的
    看来我的手册该更新了 :(
      

  12.   

    Note: In PHP 3, object properties will be serialized, but methods are lost. PHP 4 removes that limitation and restores both properties and methods.
      

  13.   

    我说几位,用PHP进行面向对象的人不多,我看我们几个交个朋友怎么样?
    我的QQ是:9999790,欢迎几位加我!
    加我的时候告诉我你用面向对象的PHP哦!