Skip to content

Edoardo Vignati

– Always looking for something awesome –

Menu
  • About me
  • Studies
  • Publications
  • Skills
  • Portfolio
  • Projects
  • Career
  • Blog
  • Travels  
Menu

How to save PHP object into SESSION variable

Posted on 03/02/202224/02/2022 by Edoardo

If you try to save an object into the $_SESSION variable, you will probably notice this error: __PHP_Incomplete_Class Object

This error occurs when an object cannot be serialized and deserialized properly. For this reason, before assigning an object to a session variable, you must serialize it using the function

$_SESSION["my_var"] = serialize($my_object);

To deserialize it you just have to call the opposite function

unserialize($_SESSION["my_var"]);

Pay attention: the unserialize function needs to know the structure of the original object, so remember also to include the declaration of the original class. Remember to call the session_start() as first function of your PHP script.


Buy Me A Coffee


This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Edoardo on [SOLVED] XMLHttpRequest error in Flutter web is a CORS error06/01/2023
  2. Fabi on [SOLVED] XMLHttpRequest error in Flutter web is a CORS error20/12/2022
  3. Edoardo on How to install hplip on Ubuntu28/11/2022
  4. Alex K on How to install hplip on Ubuntu28/11/2022

© 2023 Edoardo Vignati | Powered by Minimalist Blog WordPress Theme