Toggle navigation
Genres
Frontend (2)
JavaScript (6)
Database (2)
Linux Server (3)
Web Apps (4)
Misc (4)
Search
List
New Tutorials
Last Modified Tutorials
</>
Code examples
code
smiko
backend
php
oop
classes_objects
90magic_serialize.php
90magic_serialize.php
<?php /** Primjer pokazuje upotrebu serialize() funkcije * serialize() pretvara objekt u string koji se može spremiti u bazu, * cookie, $_SESSION ...itd **/ class MojaKlasa { public $pub1, $pub2; protected $prot; private $c,$d; public function __construct($pub1,$pub2,$prot,$c,$d){ $this->pub1=$pub1; $this->pub2=$pub2; $this->prot=$prot; $this->c=$c; $this->d=$d; } public function ispis() { echo $this->pub1."<br/>"; echo $this->pub2."<br/>"; echo $this->prot."<br/>"; echo $this->c."<br/>"; echo $this->d."<br/>"; } } //defininranje objekta $obj=new MojaKlasa('Publik1 ','Publik2 ','Protekted ','Sv c','Sv d'); //serialization - pretvaranje objekta u string $s_obj $s=serialize($obj); echo $s."<hr/>"; //unserialization - pretvaranje stringa nazad u objekt $obj2=unserialize($s); $obj2->ispis(); ?>
Reload page
Preview
W3C validation
Edit Code