Created
August 21, 2013 08:14
-
-
Save koriym/6291656 to your computer and use it in GitHub Desktop.
Serialized object singleton test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Depedency | |
{ | |
public $value; | |
} | |
class A | |
{ | |
public $dependency; | |
public function setDependency($dependency) | |
{ | |
$this->dependency = $dependency; | |
} | |
} | |
class B | |
{ | |
public $dependency; | |
public function setDependency($dependency) | |
{ | |
$this->dependency = $dependency; | |
} | |
} | |
$a = new A; | |
$b = new B; | |
$d = new Depedency; | |
$a->setDependency($d); | |
$b->setDependency($d); | |
$d->value = 10; | |
echo $a->dependency->value . PHP_EOL; | |
echo $b->dependency->value . PHP_EOL; | |
// 10 | |
// 10 | |
$saved = serialize([$a, $b, $d]); | |
file_put_contents('saved.php', $saved); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment