Skip to content

Commit

Permalink
fix: PHP Compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Sep 18, 2024
1 parent 485d1e9 commit 0367d13
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions Array_Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@
*
* @template TKey
* @template TValue
* @template-covariant TValue
* @template-implements \ArrayAccess<TKey, TValue>, \Iterator<TKey, TValue>, \Countable, \JsonSerializable
* @phpstan-require-implements \ArrayAccess<TKey, TValue>, \Iterator<TKey, TValue>, \Countable, \JsonSerializable
*
* @template-implements \ArrayAccess<TKey, TValue>
* @template-implements \Iterator<TKey, TValue>
* @template-implements \Countable
* @template-implements \JsonSerializable
*
* @phpstan-require-implements \ArrayAccess<TKey, TValue>
* @phpstan-require-implements \Iterator<TKey, TValue>
* @phpstan-require-implements \Countable
* @phpstan-require-implements \JsonSerializable
*/
trait Array_Access {
/**
* Traversible data array.
*
* @var array<int|string, mixed>
* @var array<TKey, TValue>
*/
protected array $arr_data = array();

/**
* Array of keys for the data array.
*
* @var array<string|int>
* @var array<int,TKey>
*/
protected array $arr_data_keys = array();

Expand Down Expand Up @@ -189,9 +196,9 @@ public function __serialize() {
* @param array<TKey, TValue> $data The data to unserialize.
* @return void
*/
public function __unserialize($data) {
foreach ($data as $k => $v) {
$this[$k] = $v;
public function __unserialize( $data ) {
foreach ( $data as $k => $v ) {
$this[ $k ] = $v;
}
}

Expand All @@ -207,14 +214,14 @@ public function jsonSerialize(): mixed {
/**
* Set the state of the object.
*
* @param array<TKey, TValue> $data The data to set.
* @param array{arr_data: array<TKey, TValue>} $data The data to set.
* @return static
*/
public static function __set_state( array $data): static {
public static function __set_state( array $data ): static {
$obj = new static();

foreach ($data['arr_data'] as $k => $v) {
$obj[$k] = $v;
foreach ( $data['arr_data'] as $k => $v ) {
$obj[ $k ] = $v;
}

return $obj;
Expand Down

0 comments on commit 0367d13

Please sign in to comment.