Debug.php 697 B

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