Storing A PHP Object In A Session Variable

前端 未结 3 807
無奈伤痛
無奈伤痛 2021-01-18 19:14

I\'m new to OOP and am writing one of my first classes. I work for an insurance broker and am trying to use a Class to store things about a quote, and store the Object as a

3条回答
  •  逝去的感伤
    2021-01-18 19:49

    I managed to fix it all by myself, not sure how though.

    I ensured that the page displaying the values was structured like:

    require_once("Class.php");
    session_start();
    
    $_SESSION['myObject']->printVariables();
    

    And that the page constructing the object was like:

    # Include the class
    require_once($_SERVER['DOCUMENT_ROOT'] . "/Class.php");
    
    # Instantiate a new policy
    $_SESSION['myObject'] = new quote('54');
    $_SESSION['myObject']->printVariables();
    

    I also made sure that the page displaying calling the object did not use any serialize functions, as they seemed to only cause errors.

提交回复
热议问题