How to persist data in a PHP application -


why might static variable i've initialized in class become unset? here class( 'static' ):

class events {     // static events collection     private static $events = null;      // private(unused) constructor     private function __construct() {}      // initializes class     public static function initialize($events){         self::$events = $events;             }      // returns event collection     public static function get(){         return self::$events;     } } 

i set $events this:

functions.php: include_once "events.php";  // function initialize application function init(){     // retrieve events database     $events = get_events_from_server();      // initialize events class     events::initialize($events); } 

init() called index.php. variable seems unset after index.php has loaded. post javascript server page: get_events.php request list of json encoded events. @ get_events.php static events variable null. here get_events.php:

<?php      include_once "../ccc-psl-config.php";     include_once webroot ."/includes/functions.php";     include_once webroot ."/includes/db_connect.php";     include_once webroot ."/types/events.php";      ob_start();      try{         // open database connection         $pdo = databaseconnection::open();             $events = events::get();         //$events = get_events($pdo);          if($events){             echo $events;         }         else {             echo false;         }     }     catch(exception $e){         print_r("failed events database: ".$e.getmessage());         echo false;     }      // close database connection     databaseconnection::close();      ob_end_flush(); 


Popular posts from this blog