1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* PHP Polyfill for spl_object_id() for PHP <= 7.1 |
5
|
|
|
* This file will be included even in releases which will analyze PHP 7.2, |
6
|
|
|
* there aren't any major compatibilities preventing analysis of PHP 7.2 from running in PHP 7.1. |
7
|
|
|
*/ |
8
|
|
|
if (!function_exists('spl_object_id')) { |
9
|
|
|
if (function_exists('runkit_object_id') && |
10
|
|
|
!(new ReflectionFunction('runkit_object_id'))->isUserDefined()) { |
11
|
|
|
/** |
12
|
|
|
* See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1 |
13
|
|
|
* |
14
|
|
|
* @param object $object |
15
|
|
|
* @return int The object id |
16
|
|
|
*/ |
17
|
|
|
function spl_object_id($object) : int |
18
|
|
|
{ |
19
|
|
|
return runkit_object_id($object); |
20
|
|
|
} |
21
|
|
|
} elseif (PHP_INT_SIZE === 8) { |
22
|
|
|
/** |
23
|
|
|
* See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1 |
24
|
|
|
* |
25
|
|
|
* @param object $object |
26
|
|
|
* @return int (The object id, XORed with a random number) |
27
|
|
|
*/ |
28
|
|
|
function spl_object_id($object) : int |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$hash = spl_object_hash($object); |
31
|
|
|
// Fit this into a php long (32-bit or 64-bit signed int). |
32
|
|
|
// The first 16 hex digits (64 bytes) vary, the last 16 don't. |
33
|
|
|
// Values are usually padded with 0s at the front. |
34
|
|
|
return intval(substr($hash, 1, 15), 16); |
35
|
|
|
} |
36
|
|
|
} else { |
37
|
|
|
/** |
38
|
|
|
* See https://github.com/runkit7/runkit_object_id for a faster native version for php <= 7.1 |
39
|
|
|
* |
40
|
|
|
* @param object $object |
41
|
|
|
* @return int (The object id, XORed with a random number) |
42
|
|
|
*/ |
43
|
|
|
function spl_object_id($object) : int |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$hash = spl_object_hash($object); |
46
|
|
|
// Fit this into a php long (32-bit or 64-bit signed int). |
47
|
|
|
// The first 16 hex digits (64 bytes) vary, the last 16 don't. |
48
|
|
|
// Values are usually padded with 0s at the front. |
49
|
|
|
return intval(substr($hash, 9, 7), 16); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check looks for functions that have already been defined in the same file.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.