Skip to content

Commit

Permalink
Make compatible with PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 21, 2021
1 parent 7df93f1 commit 4c5c0b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ JSON for the XP Framework ChangeLog

## 5.0.0 / 2021-10-21

* Made compatible with PHP 8.1 - add `ReturnTypeWillChange` attributes to
iterator, see https://wiki.php.net/rfc/internal_method_return_types
* Implemented xp-framework/rfc#341, dropping compatibility with XP 9
(@thekid)

Expand Down
8 changes: 7 additions & 1 deletion src/main/php/text/json/Elements.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace text\json;

use Iterator, ReturnTypeWillChange;
use lang\FormatException;
use util\Objects;

Expand All @@ -8,7 +9,7 @@
* an element from the underlying input, then returns it immediately for
* further processing instead of parsing the entire representation first.
*/
class Elements implements \Iterator {
class Elements implements Iterator {
protected $input;
protected $id= 0;
protected $current= null;
Expand All @@ -23,6 +24,7 @@ public function __construct(Input $input) {
}

/** @return void */
#[ReturnTypeWillChange]
public function rewind() {
$token= $this->input->firstToken();
if ('[' === $token) {
Expand All @@ -39,15 +41,19 @@ public function rewind() {
}

/** @return var */
#[ReturnTypeWillChange]
public function current() { return $this->current; }

/** @return var */
#[ReturnTypeWillChange]
public function key() { return $this->id; }

/** @return bool */
#[ReturnTypeWillChange]
public function valid() { return null !== $this->id; }

/** @return void */
#[ReturnTypeWillChange]
public function next() {
$token= $this->input->nextToken();
if (',' === $token) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/php/text/json/Pairs.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace text\json;

use Iterator, ReturnTypeWillChange;
use lang\FormatException;
use util\Objects;

Expand All @@ -8,7 +9,7 @@
* parses an element from the underlying input, then returns it immediately
* for further processing instead of parsing the entire representation first.
*/
class Pairs implements \Iterator {
class Pairs implements Iterator {
protected $input;
protected $key= null;
protected $value= null;
Expand Down Expand Up @@ -38,6 +39,7 @@ private function nextValue() {
}

/** @return void */
#[ReturnTypeWillChange]
public function rewind() {
$token= $this->input->firstToken();
if ('{' === $token) {
Expand All @@ -55,15 +57,19 @@ public function rewind() {
}

/** @return var */
#[ReturnTypeWillChange]
public function current() { return $this->value; }

/** @return var */
#[ReturnTypeWillChange]
public function key() { return $this->key; }

/** @return bool */
#[ReturnTypeWillChange]
public function valid() { return null !== $this->key; }

/** @return void */
#[ReturnTypeWillChange]
public function next() {
$token= $this->input->nextToken();
if (',' === $token) {
Expand Down

0 comments on commit 4c5c0b9

Please sign in to comment.