Skip to content

Declare tentative return types for Zend #7251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Zend/tests/ArrayAccess_indirect_append.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ Using indirect append on ArrayAccess object

class AA implements ArrayAccess {
private $data = [];
public function &offsetGet($name) {
public function &offsetGet($name): mixed {
if (null === $name) {
return $this->data[];
} else {
return $this->data[$name];
}
}
public function offsetSet($name, $value) {
public function offsetSet($name, $value): void {
$this->data[$name] = $value;
}
public function offsetUnset($name) {}
public function offsetExists($name) {}
public function offsetUnset($name): void {}
public function offsetExists($name): bool {}
}

$aa = new AA;
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/anon/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ class Outer {
public function getArrayAccess() {
/* create a proxy object implementing array access */
return new class($this->data) extends Outer implements ArrayAccess {
public function offsetGet($offset) { return $this->data[$offset]; }
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
public function offsetUnset($offset) { unset($this->data[$offset]); }
public function offsetExists($offset) { return isset($this->data[$offset]); }
public function offsetGet($offset): mixed { return $this->data[$offset]; }
public function offsetSet($offset, $data): void { $this->data[$offset] = $data; }
public function offsetUnset($offset): void { unset($this->data[$offset]); }
public function offsetExists($offset): bool { return isset($this->data[$offset]); }
};
}
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/anon/005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Outer {
/* create a child object implementing array access */
/* this grants you access to protected methods and members */
return new class($this->data) implements ArrayAccess {
public function offsetGet($offset) { return $this->data[$offset]; }
public function offsetSet($offset, $data) { return ($this->data[$offset] = $data); }
public function offsetUnset($offset) { unset($this->data[$offset]); }
public function offsetExists($offset) { return isset($this->data[$offset]); }
public function offsetGet($offset): mixed { return $this->data[$offset]; }
public function offsetSet($offset, $data): void { $this->data[$offset] = $data; }
public function offsetUnset($offset): void { unset($this->data[$offset]); }
public function offsetExists($offset): bool { return isset($this->data[$offset]); }
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/arg_unpack/traversable_throwing_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function test(...$args) {
}

class Foo implements IteratorAggregate {
public function getIterator() {
public function getIterator(): Traversable {
throw new Exception('getIterator');
}
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/argument_restriction_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Bug #55719 (Argument restriction should come with a more specific error message)
--FILE--
<?php
class Sub implements ArrayAccess {
public function offsetSet() {
public function offsetSet(): void {
}
}
?>
--EXPECTF--
Fatal error: Declaration of Sub::offsetSet() must be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value) in %sargument_restriction_005.php on line %d
Fatal error: Declaration of Sub::offsetSet(): void must be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void in %sargument_restriction_005.php on line %d
16 changes: 8 additions & 8 deletions Zend/tests/assign_coalesce_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ try {
var_dump($ary);

class AA implements ArrayAccess {
public function offsetExists($k) {
public function offsetExists($k): bool {
return true;
}
public function &offsetGet($k) {
public function &offsetGet($k): mixed {
$var = ["foo" => "bar"];
return $var;
}
public function offsetSet($k,$v) {}
public function offsetUnset($k) {}
public function offsetSet($k,$v): void {}
public function offsetUnset($k): void {}
}

class Dtor {
Expand All @@ -52,14 +52,14 @@ try {
var_dump($foo);

class AA2 implements ArrayAccess {
public function offsetExists($k) {
public function offsetExists($k): bool {
return false;
}
public function offsetGet($k) {
public function offsetGet($k): mixed {
return null;
}
public function offsetSet($k,$v) {}
public function offsetUnset($k) {}
public function offsetSet($k,$v): void {}
public function offsetUnset($k): void {}
}

$ary = ["foo" => new AA2];
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/assign_coalesce_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class AA implements ArrayAccess {
public function __construct($data = []) {
$this->data = $data;
}
public function &offsetGet($k) {
public function &offsetGet($k): mixed {
echo "offsetGet($k)\n";
return $this->data[$k];
}
public function offsetExists($k) {
public function offsetExists($k): bool {
echo "offsetExists($k)\n";
return array_key_exists($k, $this->data);
}
public function offsetSet($k,$v) {
public function offsetSet($k,$v): void {
echo "offsetSet($k,$v)\n";
$this->data[$k] = $v;
}
public function offsetUnset($k) { }
public function offsetUnset($k): void { }
}

$ary = new AA(["foo" => new AA, "null" => null]);
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/bug26229.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Bug #26229 (getIterator() segfaults when it returns arrays or scalars)
<?php

class array_iterator implements IteratorAggregate {
#[ReturnTypeWillChange]
public function getIterator() {
return array('foo', 'bar');
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug30346.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Bug #30346 (arrayAccess and using $this)
class Test implements ArrayAccess
{
public function __construct() { }
public function offsetExists( $offset ) { return false; }
public function offsetGet( $offset ) { return $offset; }
public function offsetSet( $offset, $data ) { }
public function offsetUnset( $offset ) { }
public function offsetExists( $offset ): bool { return false; }
public function offsetGet( $offset ): mixed { return $offset; }
public function offsetSet( $offset, $data ): void { }
public function offsetUnset( $offset ): void { }
}

$post = new Test;
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug30725.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bug #30725 (PHP segfaults when an exception is thrown in getIterator() within fo

class Test implements IteratorAggregate
{
function getIterator()
function getIterator(): Traversable
{
throw new Exception();
}
Expand Down
9 changes: 5 additions & 4 deletions Zend/tests/bug31683.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ class Foo implements ArrayAccess {
$test = 'bug';
}

function offsetget($test) {
function offsetget($test): mixed {
var_dump($test);
$test = 'bug';
return 123;
}

function offsetset($test, $val) {
function offsetset($test, $val): void {
var_dump($test);
var_dump($val);
$test = 'bug';
$val = 'bug';
}

function offsetexists($test) {
function offsetexists($test): bool {
var_dump($test);
$test = 'bug';
return true;
}

function offsetunset($test) {
function offsetunset($test): void {
var_dump($test);
$test = 'bug';
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug32252.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ Bug #32252 (Segfault when offsetSet throws an Exception (only without debug))

class Test implements ArrayAccess
{
function offsetExists($offset)
function offsetExists($offset): bool
{
echo __METHOD__ . "($offset)\n";
return false;
}

function offsetGet($offset)
function offsetGet($offset): mixed
{
echo __METHOD__ . "($offset)\n";
return null;
}

function offsetSet($offset, $value)
function offsetSet($offset, $value): void
{
echo __METHOD__ . "($offset, $value)\n";
throw new Exception("Ooops");
}

function offsetUnset($offset)
function offsetUnset($offset): void
{
echo __METHOD__ . "($offset)\n";
}
Expand Down
14 changes: 7 additions & 7 deletions Zend/tests/bug32674.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ class collection implements Iterator {
public function __construct() {
}

public function rewind() {
public function rewind(): void {
reset($this->_elements);
}

public function count() {
public function count(): int {
return count($this->_elements);
}

public function current() {
public function current(): mixed {
$element = current($this->_elements);
return $element;
}

public function next() {
public function next(): void {
$element = next($this->_elements);
return $element;
$element;
}

public function key() {
public function key(): mixed {
$this->_fillCollection();
$element = key($this->_elements);
return $element;
}

public function valid() {
public function valid(): bool {
throw new Exception('shit happened');

return ($this->current() !== false);
Expand Down
10 changes: 5 additions & 5 deletions Zend/tests/bug32993.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ class Test implements Iterator {

public $arr = array();

public function rewind() { return reset($this->arr); }
public function current() { throw new Exception(); }
public function key() { return key($this->arr); }
public function next() { return next($this->arr); }
public function valid() { return (current($this->arr) !== false); }
public function rewind(): void { reset($this->arr); }
public function current(): mixed { throw new Exception(); }
public function key(): mixed { return key($this->arr); }
public function next(): void { next($this->arr); }
public function valid(): bool { return (current($this->arr) !== false); }
}

$t = new Test();
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug33710.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Bug #33710 (ArrayAccess objects doesn't initialize $this)

class Foo implements ArrayAccess
{
function offsetExists($offset) {/*...*/}
function offsetGet($offset) {/*...*/}
function offsetSet($offset, $value) {/*...*/}
function offsetUnset($offset) {/*...*/}
function offsetExists($offset): bool { return true;}
function offsetGet($offset): mixed { return null; }
function offsetSet($offset, $value): void {/*...*/}
function offsetUnset($offset): void {/*...*/}

function fail()
{
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug39297.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ class MyTree implements ArrayAccess {
public $parent;
public $children = array();

public function offsetExists($offset) {
public function offsetExists($offset): bool {
}

public function offsetUnset($offset) {
public function offsetUnset($offset): void {
}

public function offsetSet($offset, $value) {
public function offsetSet($offset, $value): void {
echo "offsetSet()\n";
$cannonicalName = strtolower($offset);
$this->children[$cannonicalName] = $value;
$value->parent = $this;
}

public function offsetGet($offset) {
public function offsetGet($offset): mixed {
echo "offsetGet()\n";
$cannonicalName = strtolower($offset);
return $this->children[$cannonicalName];
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug40833.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ Bug #40833 (Crash when using unset() on an ArrayAccess object retrieved via __ge
$this->entity->whatever = null;
}

function offsetUnset($offset)
function offsetUnset($offset): void
{
$this->clear();
// $this->entity->{$this->name} = null;
}

function offsetSet($offset, $value)
function offsetSet($offset, $value): void
{
}

function offsetGet($offset)
function offsetGet($offset): mixed
{
return 'Bogus ';
}

function offsetExists($offset)
function offsetExists($offset): bool
{
}
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/tests/bug41209.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class cache implements ArrayAccess
{
private $container = array();

public function offsetGet($id) {}
public function offsetGet($id): mixed {}

public function offsetSet($id, $value) {}
public function offsetSet($id, $value): void {}

public function offsetUnset($id) {}
public function offsetUnset($id): void {}

public function offsetExists($id)
public function offsetExists($id): bool
{
return isset($this->containers[(string) $id]);
}
Expand Down
10 changes: 5 additions & 5 deletions Zend/tests/bug49269.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Bug #49269 (Ternary operator fails on Iterator object when used inside foreach d
class TestObject implements Iterator
{
public $n = 0;
function valid()
function valid(): bool
{
return ($this->n < 3);
}
function current() {return $this->n;}
function next() {$this->n++;}
function key() { }
function rewind() {$this->n = 0;}
function current(): mixed {return $this->n;}
function next(): void {$this->n++;}
function key(): mixed { }
function rewind(): void {$this->n = 0;}
}


Expand Down
Loading