Skip to content

Commit 7d1b282

Browse files
authored
Added method Debug::getRefCount($object). (#4331)
1 parent aac9078 commit 7d1b282

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Debug.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace Hyperf\Testing;
13+
14+
class Debug
15+
{
16+
public static function getRefCount($object): string
17+
{
18+
ob_start();
19+
debug_zval_dump($object);
20+
$data = ob_get_clean();
21+
22+
preg_match('/refcount\((\w+)\)/U', $data, $matched);
23+
$result = $matched[1];
24+
if(is_numeric($result)){
25+
return bcsub($result, '1');
26+
}
27+
28+
return $matched[1];
29+
}
30+
}

0 commit comments

Comments
 (0)