Problem with sessions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • darko

    #1

    Problem with sessions

    Hi, is it possible to put classes in SESSION variables ?

    I've created a class named ObjContratto that I use in this way:

    $myContr = new ObjContratto;
    $myContr->settore = 10;

    now I need to use the same object, $myContr, in another page. So I put
    it in a SESSION variable in this way:

    session_start() ;
    $_SESSION['contr'] = $myContr;


    and retrieve the _same_ object from another page in this way:

    session_start() ;
    $myContr = $_SESSION['contr'];

    but when I try to retrieve values from $myContr in this way:

    $s = $myContr->settore;

    it doesn't work, $s is sadly empty.

    If I do an

    echo $myContr;

    it says "Object", so the session should work.

    any idea?
    tnx

    darko
    --
    "Cosa sono i milioni, quando in cambio ti danno le scarpe ?"

  • Anders K. Madsen

    #2
    Re: Problem with sessions

    On Tue, 20 Jul 2004 16:04:04 +0200
    darko <darko@spam.org > wrote:

    [snip][color=blue]
    > any idea?[/color]

    You can't just store an object... That'll yield the same result as:
    echo $object;

    So, RTFM, as the man said. ;-)
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    Madsen

    --
    Anders K. Madsen --- http://lillesvin.linux.dk

    "There are 10 types of people in the world.
    Those who understand binary - and those who don't."

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFA/SiblNHJe/JASHcRAoPqAJwOj sJ45KlS3UeYGv2g 9FEONcGaMQCfV4t Z
    5QYtxlhSKvJmw0R k2FgHypw=
    =fMky
    -----END PGP SIGNATURE-----

    Comment

    • darko

      #3
      Re: Problem with sessions

      Anders K. Madsen wrote:
      [color=blue]
      > You can't just store an object... That'll yield the same result as:
      > echo $object;
      >
      > So, RTFM, as the man said. ;-)
      > http://dk.php.net/manual/en/language...ialization.php[/color]

      that's ok. I've just put in session the variables I needed.

      tnx
      darko

      --
      "Cosa sono i milioni, quando in cambio ti danno le scarpe ?"

      Comment

      • Pedro Graca

        #4
        Re: Problem with sessions

        Anders K. Madsen wrote:[color=blue]
        > You can't just store an object... That'll yield the same result as:
        > echo $object;[/color]

        I don't do OOP -- but this works for me:

        ========
        <?php // o0.php
        class Obj {
        var $y;
        function invert() {
        return str_rot13($this->y);
        }
        }
        ?>
        --------
        <?php // o1.php
        require_once 'o0.php';

        $x = new Obj();
        $x->y = 'Pedro';
        session_start() ;
        $_SESSION['o'] = $x;
        echo 'go to <a href="o2.php">n ext page</a>';
        ?>
        --------
        <?php // o2.php
        require_once 'o0.php';

        session_start() ;
        $oldobj = $_SESSION['o'];
        echo $oldobj->invert();
        ?>
        ========


        Notice that the object definition in o2.php is loaded from o0.php
        before the object is loaded from the $_SESSION array.


        --
        USENET would be a better place if everybody read: | to email me: use |
        http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
        http://www.netmeister.org/news/learn2quote2.html | header, textonly |
        http://www.expita.com/nomime.html | no attachments. |

        Comment

        • darko

          #5
          Re: Problem with sessions

          Pedro Graca wrote:
          [color=blue]
          > --------
          > <?php // o2.php
          > require_once 'o0.php';
          >
          > session_start() ;
          > $oldobj = $_SESSION['o'];
          > echo $oldobj->invert();
          > ?>
          > ========[/color]

          yes, this worked with me too, but I needed values stored in the object
          instanced in the first page.

          darko
          --
          "Cosa sono i milioni, quando in cambio ti danno le scarpe ?"

          Comment

          Working...