<?php
class Foo {
private $data = array("Foo");
public function __sleep() {
return array("data");
}
}
class Bar implements Serializable{
private $data = array("Bar");
public function serialize() {
return serialize($data);
}
public function unserialize($data) {
$this->data = unserialize($data);
}
}
$foo = new Foo;
$bar = new Bar;
var_dump(serialize($foo));
var_dump(serialize($bar));
Deprecated: Bar implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/uf1cb on line 10
string(50) "O:3:"Foo":1:{s:9:" Foo data";a:1:{i:0;s:3:"Foo";}}"
Warning: Undefined variable $data in /in/uf1cb on line 13
string(16) "C:3:"Bar":2:{N;}"
Output for 8.0.0 - 8.0.30
string(50) "O:3:"Foo":1:{s:9:" Foo data";a:1:{i:0;s:3:"Foo";}}"
Warning: Undefined variable $data in /in/uf1cb on line 13
string(16) "C:3:"Bar":2:{N;}"
Fatal error: Interface 'Serializable' not found in /in/uf1cb on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'Serializable' not found in /in/uf1cb on line 10
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/uf1cb on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/uf1cb on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/uf1cb on line 4
Process exited with code 255.