Skip to content

Instantly share code, notes, and snippets.

@koriym
Created August 21, 2013 08:14
Show Gist options
  • Save koriym/6291656 to your computer and use it in GitHub Desktop.
Save koriym/6291656 to your computer and use it in GitHub Desktop.
Serialized object singleton test
<?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