Skip to content

Instantly share code, notes, and snippets.

@xcombelle
Last active September 3, 2016 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcombelle/cc8c391e93d01dfe9568bf634a656767 to your computer and use it in GitHub Desktop.
Save xcombelle/cc8c391e93d01dfe9568bf634a656767 to your computer and use it in GitHub Desktop.
php problem
#!/usr/bin/env php
<?php
class Dangerous {
private $object;
public function __construct()
{
$this->object = new \stdClass();;
}
public function exec() {
echo "dangerous";
}
}
class NotDangerous {
public function exec() {
echo "not dangerous";
}
}
class SegfaultScenario
{
private $circular_reference;
private $object;
public function __construct()
{
$this->circular_reference = $this;
$this->notDangerous = new \NotDangerous();
}
public function __destruct()
{
if (!$this->notDangerous) {
return;
}
$notUsed = new \Dangerous();;
$this->notDangerous->exec();
}
}
new SegfaultScenario();
gc_collect_cycles();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment