b2pweb /
bdf-form
| 1 | <?php |
||||
| 2 | |||||
| 3 | if (!class_exists(WeakReference::class)) { |
||||
| 4 | /** |
||||
| 5 | * Pseudo polyfill for get the WeakReference API on PHP < 7.4 |
||||
| 6 | * |
||||
| 7 | * https://www.php.net/manual/en/class.weakreference.php |
||||
| 8 | * |
||||
| 9 | * @template T as object |
||||
| 10 | */ |
||||
| 11 | class WeakReference |
||||
| 12 | { |
||||
| 13 | /** |
||||
| 14 | * @var T |
||||
| 15 | */ |
||||
| 16 | private $obj; |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * WeakReference constructor. |
||||
| 20 | * |
||||
| 21 | * @param T $obj |
||||
| 22 | */ |
||||
| 23 | private function __construct($obj) |
||||
| 24 | { |
||||
| 25 | $this->obj = $obj; |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * Get a weakly referenced Object |
||||
| 30 | * |
||||
| 31 | * @return T|null |
||||
| 32 | */ |
||||
| 33 | public function get() |
||||
| 34 | { |
||||
| 35 | return $this->obj; |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 36 | } |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * Create a new weak reference |
||||
| 40 | * |
||||
| 41 | * @param T $obj |
||||
| 42 | * |
||||
| 43 | * @return WeakReference |
||||
| 44 | */ |
||||
| 45 | public static function create($obj): WeakReference |
||||
| 46 | { |
||||
| 47 | return new self($obj); |
||||
|
0 ignored issues
–
show
The call to
WeakReference::__construct() has too many arguments starting with $obj.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. Loading history...
|
|||||
| 48 | } |
||||
| 49 | } |
||||
| 50 | } |
||||
| 51 |