classa.inc: class A {var $one = 1; function show_one() {echo $this - one;}} page1.php: include("classa.inc"); $a = new A; $s = serialize($a); / / store $s somewhere where page2.php can find it. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp); page2.php: / / this is needed for the unserialize to work properly. include("classa.inc"); $s = implode("", @file("store")); $a = unserialize($s); / / now use the function show_one() of the $a object. $a - show_one();
?php classa.inc: class A {var $one = 1; function show_one() {echo $this - one;}}? page1.php: ?php include("classa.inc"); $a = new A; $s = serialize($a); / / enregistrez $s où la page2.php pourra le trouver. $fp = fopen("store", "w"); fputs($fp, $s); fclose($fp);? page2.php: ?php / / Ceci est nécessaire pour que unserialize() fonctionne correctement include("classa.inc"); $s = implode("", @file("store")); unserialize($s); / / maintenant, utilisez la méthode show_one de l'objet $a. $a - show_one();?