diff options
author | Gabriel Caruso <carusogabriel34@gmail.com> | 2019-05-31 00:45:32 -0300 |
---|---|---|
committer | Gabriel Caruso <carusogabriel34@gmail.com> | 2020-08-02 01:29:56 +0200 |
commit | e3d06fc79db5af5dba3f4a65bd24b3712711f1ae (patch) | |
tree | 7d87cf3b51735e17d9ddf8fede8de93c197ceaf0 /Zend/tests/return_types | |
parent | 650801ce4520af9d910b1d11a4951aaccf69624a (diff) | |
download | php-git-e3d06fc79db5af5dba3f4a65bd24b3712711f1ae.tar.gz |
Ensure correct signatures for magic methods
Diffstat (limited to 'Zend/tests/return_types')
-rw-r--r-- | Zend/tests/return_types/019.phpt | 5 | ||||
-rw-r--r-- | Zend/tests/return_types/033.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/034.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/035.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/036.phpt | 11 | ||||
-rw-r--r-- | Zend/tests/return_types/037.phpt | 11 | ||||
-rw-r--r-- | Zend/tests/return_types/038.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/039.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/040.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/041.phpt | 10 | ||||
-rw-r--r-- | Zend/tests/return_types/042.phpt | 24 | ||||
-rw-r--r-- | Zend/tests/return_types/043.phpt | 29 | ||||
-rw-r--r-- | Zend/tests/return_types/044.phpt | 10 |
13 files changed, 158 insertions, 2 deletions
diff --git a/Zend/tests/return_types/019.phpt b/Zend/tests/return_types/019.phpt index 4be32b2474..652548c3f9 100644 --- a/Zend/tests/return_types/019.phpt +++ b/Zend/tests/return_types/019.phpt @@ -1,10 +1,11 @@ --TEST-- -__clone cannot declare a return type +__clone can only declare void return --FILE-- <?php class Foo { function __clone() : Foo {} } +?> --EXPECTF-- -Fatal error: %s::%s() cannot declare a return type in %s on line %d +Fatal error: Foo::__clone(): Return type must be void when declared in %s on line %d diff --git a/Zend/tests/return_types/033.phpt b/Zend/tests/return_types/033.phpt new file mode 100644 index 0000000000..e725465253 --- /dev/null +++ b/Zend/tests/return_types/033.phpt @@ -0,0 +1,10 @@ +--TEST-- +__set can only declare void return +--FILE-- +<?php +class Foo { + function __set($name, $value) : string {} +} +?> +--EXPECTF-- +Fatal error: Foo::__set(): Return type must be void when declared in %s on line %d diff --git a/Zend/tests/return_types/034.phpt b/Zend/tests/return_types/034.phpt new file mode 100644 index 0000000000..50324208cb --- /dev/null +++ b/Zend/tests/return_types/034.phpt @@ -0,0 +1,10 @@ +--TEST-- +__isset can only declare a boolean return type +--FILE-- +<?php +class Foo { + function __isset($name) : \stdClass|bool {} +} +?> +--EXPECTF-- +Fatal error: Foo::__isset(): Return type must be bool when declared in %s on line %d diff --git a/Zend/tests/return_types/035.phpt b/Zend/tests/return_types/035.phpt new file mode 100644 index 0000000000..fa2d331f55 --- /dev/null +++ b/Zend/tests/return_types/035.phpt @@ -0,0 +1,10 @@ +--TEST-- +__unset can only declare void return +--FILE-- +<?php +class Foo { + function __unset($name) : bool {} +} +?> +--EXPECTF-- +Fatal error: Foo::__unset(): Return type must be void when declared in %s on line %d diff --git a/Zend/tests/return_types/036.phpt b/Zend/tests/return_types/036.phpt new file mode 100644 index 0000000000..2f0847f21b --- /dev/null +++ b/Zend/tests/return_types/036.phpt @@ -0,0 +1,11 @@ +--TEST-- +__toString can only declare string return type +--FILE-- +<?php +class Foo { + public function __toString(): bool { + } +} +?> +--EXPECTF-- +Fatal error: Declaration of Foo::__toString(): bool must be compatible with Stringable::__toString(): string in %s on line %d diff --git a/Zend/tests/return_types/037.phpt b/Zend/tests/return_types/037.phpt new file mode 100644 index 0000000000..34569e494e --- /dev/null +++ b/Zend/tests/return_types/037.phpt @@ -0,0 +1,11 @@ +--TEST-- +__debugInfo can only declare array as return type +--FILE-- +<?php +class Foo { + public function __debugInfo(): bool { + } +} +?> +--EXPECTF-- +Fatal error: Foo::__debugInfo(): Return type must be ?array when declared in %s on line %d diff --git a/Zend/tests/return_types/038.phpt b/Zend/tests/return_types/038.phpt new file mode 100644 index 0000000000..a51658c454 --- /dev/null +++ b/Zend/tests/return_types/038.phpt @@ -0,0 +1,10 @@ +--TEST-- +__serialize can only declare array as return type +--FILE-- +<?php +class Foo { + public function __serialize(): \stdClass {} +} +?> +--EXPECTF-- +Fatal error: Foo::__serialize(): Return type must be array when declared in %s on line %d diff --git a/Zend/tests/return_types/039.phpt b/Zend/tests/return_types/039.phpt new file mode 100644 index 0000000000..15a420757c --- /dev/null +++ b/Zend/tests/return_types/039.phpt @@ -0,0 +1,10 @@ +--TEST-- +__unserialize can only declare void return +--FILE-- +<?php +class Foo { + public function __unserialize(array $data): array {} +} +?> +--EXPECTF-- +Fatal error: Foo::__unserialize(): Return type must be void when declared in %s on line %d diff --git a/Zend/tests/return_types/040.phpt b/Zend/tests/return_types/040.phpt new file mode 100644 index 0000000000..736a400f44 --- /dev/null +++ b/Zend/tests/return_types/040.phpt @@ -0,0 +1,10 @@ +--TEST-- +__sleep can only declare return as array +--FILE-- +<?php +class Foo { + public function __sleep(): bool|int {} +} +?> +--EXPECTF-- +Fatal error: Foo::__sleep(): Return type must be array when declared in %s on line %d diff --git a/Zend/tests/return_types/041.phpt b/Zend/tests/return_types/041.phpt new file mode 100644 index 0000000000..783e1444bc --- /dev/null +++ b/Zend/tests/return_types/041.phpt @@ -0,0 +1,10 @@ +--TEST-- +__wakeup can only declare return void +--FILE-- +<?php +class Foo { + public function __wakeup(): bool {} +} +?> +--EXPECTF-- +Fatal error: Foo::__wakeup(): Return type must be void when declared in %s on line %d diff --git a/Zend/tests/return_types/042.phpt b/Zend/tests/return_types/042.phpt new file mode 100644 index 0000000000..069e0228ff --- /dev/null +++ b/Zend/tests/return_types/042.phpt @@ -0,0 +1,24 @@ +--TEST-- +__debugInfo can declare union return type +--FILE-- +<?php +class UnionType { + public function __debugInfo(): array|null {} +} + +class UnionType2 { + public function __debugInfo(): null|array {} +} + +class UnionTypeOldStyle { + public function __debugInfo(): ?array {} +} + +class JustAnArray { + public function __debugInfo(): array {} +} + +echo 'No problems!'; +?> +--EXPECT-- +No problems! diff --git a/Zend/tests/return_types/043.phpt b/Zend/tests/return_types/043.phpt new file mode 100644 index 0000000000..ecc5660c62 --- /dev/null +++ b/Zend/tests/return_types/043.phpt @@ -0,0 +1,29 @@ +--TEST-- +Some magic methods can declare mixed return type +--FILE-- +<?php +class Foo { + public function __get($name): bool {} + public function __call($name, $args): string {} + public static function __callStatic($name, $args): self {} + public function __invoke(): self {} +} + +class Bar { + public function __get($name): string|array {} + public function __call($name, $args): int|float {} + public static function __callStatic($name, $args): ?object {} + public function __invoke(): Foo|int {} +} + +class Baz { + public function __get($name): mixed {} + public function __call($name, $args): mixed {} + public static function __callStatic($name, $args): mixed {} + public function __invoke(): mixed {} +} + +echo 'Okay!'; +?> +--EXPECT-- +Okay! diff --git a/Zend/tests/return_types/044.phpt b/Zend/tests/return_types/044.phpt new file mode 100644 index 0000000000..3b708a05a7 --- /dev/null +++ b/Zend/tests/return_types/044.phpt @@ -0,0 +1,10 @@ +--TEST-- +__set_state can only declare object as return +--FILE-- +<?php +class Foo { + public static function __set_state($properties): bool {} +} +?> +--EXPECTF-- +Fatal error: Foo::__set_state(): Return type must be object when declared in %s on line %d |