php - Assign Session Values Via Object -
i have been trying assign/change/update session values within object.
what trying create session , assign value in object format , update values object called/initiated.
<?php class session { var $namespace; //null default var $session; //run session essantials public function __construct($sessionname=null, $assignedvalue=null, $booleneroftype=null){ $this->namespace = (!empty($sessionname))?$sessionname:null; if(!empty($_session[$sessionname])){ if(!empty($assignedvalue)){ //this overwrites existing value of session $_session[$sessionname] = $assignedvalue? $assignedvalue : new stdclass; }else{//end of if $_session[$sessionname] = (!empty($_session[$sessionname])==true)? $_session[$sessionname] : new stdclass; } }elseif(!isset($_session[$sessionname]) or empty($_session[$sessionname])){//end of if //$_session[$sessionname] = ($assignedvalue==null)? (new stdclass): function($assignedvalue){ foreach($assignedvalue $val){}}; $_session[$sessionname]== new stdclass; }//end of else of if $this->session = $_session[$sessionname]; foreach($this->session $num=>$val){ $this->$num=$val; } foreach($_session[$sessionname] $num=>$val){ $this->$num=$val; } //debug::dump($this); unset($this->session); return $this; }//end of function static public function unsetsession($sessionname){ unset($_session[$sessionname]); return true; }//end of function public function setsessionvalue($valueobject, $obj){ $sessionname = $obj->namespace; $_session[$sessionname]=$valueobject; }//end of function public function __destruct(){ //$reassignsession = $this->session; $this->__construct($this->namespace); $sessionname = $this->namespace; //debug::dump($_session); $methodsofclass = (get_class_methods ($this )); $valueobject = new stdclass; foreach($this $id=> $value){ if(!in_array($id, $methodsofclass) , $id!= 'namespace' , $id!= 'session'){ $valueobject->$id=$value; }//end of if }//end of foreach foreach($_session[$sessionname] $num=>$val){ $this->$num=$val; } $this->setsessionvalue($valueobject, $this); return @$this->session; }//end of function }//end of class $session = new session('somename'); $session->var1 = 1; $session->var2 = 'some value'; //and session ends /* $_session['somename'] = object(session)#n { var1 => 1, var2=> 'some value' } */ ?>
my code has mistakes because have been trying things.
trying create logic.
how can this?
tried using __desctruct() not make work.
have been trying many things, lost path.
in advance
Comments
Post a Comment