object persistence in php

后端 未结 7 2260
孤城傲影
孤城傲影 2020-12-14 02:48

I am fairly new to web programming, I have mainly used java to create desktop applications in the past.

I\'m trying to figure out how to create persistent objects in

7条回答
  •  难免孤独
    2020-12-14 03:09

    Though it may not be the prettiest solution, but you can use SESSIONS for this matter.

    class SomeObject{
    
        public function __costructor{
            $_SESSION['object'] = serialize($this);
        }
    
    }
    

    and on another page, you can call the object simply with:

    $object = unserialize($_SESSION['object']);
    

    Though ofcourse this approach seems the easiest. It should come with utmost precaution:

    1. Know that sessions depending on the traffic of your server should not be too large in size as many users concurrently ask for each of these sessions. Scale the size at your own discretion.

    2. always serialize and unserialize as sessions not done so will misbehave.

    What ever sails your boat. Do so at your own mindful analyzation. goodluck

提交回复
热议问题