unserialize

unserialize -- Creates a PHP value from a stored representation

Description

mixed unserialize ( string str)

הערה : It' s possible to set a callback-function which will be called , if an undefined class should be instanciated during unserializing . (to prevent getting an incomplete object "__PHP_Incomplete_Class" . ) Use your php.ini , ini_set( ) or .htaccess-file to define 'unserialize_callback_func ' . Everytime an undefined class should be instanciated , it ' ll be called .

דוגמה 1 . unserialize_callback_func example

 
$serialized_object='

 
O:1

 
:"a":1

 
:{s:5

 
:"value";s:3

 
:"100"

 
;}'

 
;

 
ini_set('unserialize_callback_func'

 
,'mycallback')

 
;

 
/

 
/

 
set

 
your

 
callback_function

 
function

 
mycallback($classname

 
)

 
{

 
/

 
/

 
just

 
include

 
a

 
file

 
containing

 
your

 
classdefinition

 
/

 
/

 
you

 
get

 
$classname

 
to

 
figure

 
out

 
which

 
classdefinition

 
is

 
required

 
}





הערה :

דוגמה 2 . unserialize( ) example

 
/

 
/

 
Here

 
,

 
we

 
use

 
unserialize(

 
)

 
to

 
load

 
session

 
data

 
to

 
the

 
/

 
/

 
$session_data

 
array

 
from

 
the

 
string

 
selected

 
from

 
a

 
database

 
.

 
/

 
/

 
This

 
example

 
complements

 
the

 
one

 
described

 
with

 
serialize()

 
.

 
$conn

 
=

 
odbc_connect

 
("webdb"

 
,

 
"php"

 
,

 
"chicken")

 
;

 
$stmt

 
=

 
odbc_prepare

 
($conn

 
,

 
"SELECT

 
data

 
FROM

 
sessions

 
WHERE

 
id

 
=

 
?")

 
;

 
$sqldata

 
=

 
array

 
($PHP_AUTH_USER)

 
;

 
if

 
(!odbc_execute

 
($stmt

 
,

 
$sqldata

 
)

 
|

 
|

 
!odbc_fetch_into

 
($stmt

 
,

 
$tmp)

 
)

 
{

 
/

 
/

 
if

 
the

 
execute

 
or

 
fetch

 
fails

 
,

 
initialize

 
to

 
empty

 
array

 
$session_data

 
=

 
array()

 
;

 
}

 
else

 
{

 
/

 
/

 
we

 
should

 
now

 
have

 
the

 
serialized

 
data

 
in

 
$tmp[0]

 
.

 
$session_data

 
=

 
unserialize

 
($tmp[0])

 
;

 
if

 
(!is_array

 
($session_data)

 
)

 
{

 
/

 
/

 
something

 
went

 
wrong

 
,

 
initialize

 
to

 
empty

 
array

 
$session_data

 
=

 
array()

 
;

 
    }

 
}