<?php
/**
*class Foo
*{
* protected $bar = null;
*
* public function __construct($bar = null)
* {
* $this->bar = $bar;
* }
*}
*
* The class above represents the serialized, base64_encoded string below.
*/
$serialized = 'TzozOiJGb28iOjE6e3M6NjoiACoAYmFyIjtzOjM6ImJheiI7fQ==';
class Foo
{
public $bar = null;
public function getBar() { return $this->bar; }
}
var_dump(addslashes(base64_decode($serialized)));
$class = unserialize(base64_decode($serialized));
var_dump($class);
var_dump($class->getBar());
- Output for 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- string(45) "O:3:\"Foo\":1:{s:6:\"\0*\0bar\";s:3:\"baz\";}"
object(Foo)#1 (1) {
["bar"]=>
string(3) "baz"
}
string(3) "baz"
- Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
- string(45) "O:3:\"Foo\":1:{s:6:\"\0*\0bar\";s:3:\"baz\";}"
object(Foo)#1 (2) {
["bar"]=>
NULL
["bar":protected]=>
string(3) "baz"
}
NULL
preferences:
148.21 ms | 408 KiB | 5 Q