<?php
class TestClass
{
public function __destruct()
{
App::$flg = true;
}
}
class App
{
public static $flg = false;
public static function main()
{
$methods = array_filter(
(new \ReflectionClass(__CLASS__))->getMethods(),
function (\ReflectionMethod $r) {
return preg_match('/^test/', $r->getName());
}
);
array_walk($methods, function (\ReflectionMethod $r) {
$r->invoke(null, null);
});
}
public static function testArray()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = array($aa);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testObject()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \stdClass();
$bb->aa = $aa;
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testSplFixedArray()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \SplFixedArray(1);
$bb[0] = $aa;
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testSplObjectStorage()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \SplObjectStorage();
$bb->attach($aa);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testArrayObject()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \ArrayObject([$aa]);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testSplDoublyLinkedList()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \SplDoublyLinkedList();
$bb->push($aa);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testSplMaxHeap()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \SplMaxHeap();
$bb->insert($aa);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
public static function testSplPriorityQueue()
{
self::$flg = false;
call_user_func(function () {
$aa = new TestClass();
$bb = new \SplPriorityQueue();
$bb->insert($aa, 1);
$aa->bb = $bb;
});
gc_collect_cycles();
printf("%s: %s\n", __FUNCTION__, var_export(self::$flg, true));
}
}
App::main();
preferences:
58.56 ms | 402 KiB | 5 Q