-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Bug10622B; | ||
|
||
/** | ||
* @template T of array<mixed> | ||
*/ | ||
class FooBoxedArray | ||
{ | ||
/** @var T */ | ||
private $value; | ||
|
||
/** | ||
* @param T $value | ||
*/ | ||
public function __construct(array $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return T | ||
*/ | ||
public function get(): array | ||
{ | ||
return $this->value; | ||
} | ||
} | ||
|
||
/** | ||
* @template TKey of object|array<mixed> | ||
* @template TValue of object|array<mixed> | ||
*/ | ||
class FooMap | ||
{ | ||
/** | ||
* @var array<int, array{ | ||
* \WeakReference<(TKey is object ? TKey : FooBoxedArray<TKey>)>, | ||
* \WeakReference<(TValue is object ? TValue : FooBoxedArray<TValue>)> | ||
* }> | ||
*/ | ||
protected $weakKvByIndex = []; | ||
|
||
/** | ||
* @template T of TKey|TValue | ||
* | ||
* @param T $value | ||
* | ||
* @return (T is object ? T : FooBoxedArray<T>) | ||
*/ | ||
protected function boxValue($value): object | ||
{ | ||
return is_array($value) | ||
? new FooBoxedArray($value) | ||
: $value; | ||
} | ||
|
||
/** | ||
* @template T of TKey|TValue | ||
* | ||
* @param (T is object ? T : FooBoxedArray<T>) $value | ||
* | ||
* @return T | ||
*/ | ||
protected function unboxValue(object $value) | ||
{ | ||
return $value instanceof FooBoxedArray | ||
? $value->get() | ||
: $value; | ||
} | ||
} |