Home > DeveloperSection > Forums > get reference variable in php using session_decode result
john rob

Total Post:108

Posted on    November-01-2014 12:04 AM

 PHP Session 

 1 Reply(s)
 890  View(s)
Rate this:
I noticed that the PHP session_decode() function has an object type for PHP reference variables signified by 'R'. However, I can't seem to find out how to get session_decode() to output this object type. If I assign a reference variable to $_SESSION, and then call session_decode(), the reference variable is represented by session_decode() as having the same object type as the variable it references and not 'R'. What is the use case for the session_decode object type of 'R'?

Jeet Verma
Jeet Verma

Total Post:110

Posted on    November-01-2014 12:06 AM

For session_encode to encode a variable as a reference, the referenced variable needs to be in session too. If it's not in session, then it will encode it as the original type.

$foo = 'bar';
$_SESSION['foo'] = $foo;
$_SESSION['bar'] = &$_SESSION['foo'];
$_SESSION['baz'] = &$foo;
$_SESSION['hey'] = &$foo;



Don't want to miss updates? Please click the below button!

Follow MindStick