PHP expert |
|
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* __sleep / __wakeup
*
* @license http://www.gnu.org/licenses/gpl.html
* @author Stijn Leenknegt <stijnleenknegt@gmail.com>
* @version Versie 1.0
* @package noob_packages
*/
// full error reporting
error_reporting( E_ALL );
session_start();
class A
{
public $aVar;
public function __construct( $val )
{
$this->aVar = $val;
}
public function __sleep()
{
return array( 'aVar' ); // ALTIJD EEN ARRAY RETURNEN , LET OP DE VARIABLE SIGNIFICATIE!
}
public function __wakeup()
{
//hier kan je vanalles inzetten , bv andere functie aanroepen
//$this->give();
}
public function give()
{
return $this->aVar;
}
}
$obj = new A('stijn');
$_SESSION['t'] = serialize( $obj );
$obj = array( 'stijn' , 'ibrahim' , 'pieter' );
echo "<pre>";
var_dump( $obj );
echo "</pre>";
$obj = unserialize( $_SESSION['t'] );
echo $obj->give();
?>
<?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * __sleep / __wakeup * * @license http://www.gnu.org/licenses/gpl.html * @author Stijn Leenknegt <stijnleenknegt@gmail.com> * @version Versie 1.0 * @package noob_packages */ // full error reporting class A { public $aVar; public function __construct( $val ) { $this->aVar = $val; } public function __sleep() { return array( 'aVar' ); // ALTIJD EEN ARRAY RETURNEN , LET OP DE VARIABLE SIGNIFICATIE! } public function __wakeup() { //hier kan je vanalles inzetten , bv andere functie aanroepen //$this->give(); } public function give() { return $this->aVar; } } $obj = new A('stijn'); $obj = array( 'stijn' , 'ibrahim' , 'pieter' ); ?>
aub |