From c0b5d91a4ccd7071cb871dad111e766f4687e71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sun, 4 Jul 2021 23:18:59 +0200 Subject: [PATCH 1/2] Various ext/spl stub fixes --- ext/spl/spl_array.stub.php | 40 ++++++++++------------------------ ext/spl/spl_directory.stub.php | 4 ++-- ext/spl/spl_iterators.stub.php | 14 ++++++------ 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/ext/spl/spl_array.stub.php b/ext/spl/spl_array.stub.php index 303565213a6cb..81a4a8a76d68f 100644 --- a/ext/spl/spl_array.stub.php +++ b/ext/spl/spl_array.stub.php @@ -6,29 +6,17 @@ class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Count { public function __construct(array|object $array = [], int $flags = 0, string $iteratorClass = ArrayIterator::class) {} - /** - * @param string|int $key - * @return bool - */ - public function offsetExists($key) {} + /** @return bool */ + public function offsetExists(mixed $key) {} - /** - * @param string|int $key - * @return mixed - */ - public function offsetGet($key) {} + /** @return mixed */ + public function offsetGet(mixed $key) {} - /** - * @param string|int $key - * @return void - */ - public function offsetSet($key, mixed $value) {} + /** @return void */ + public function offsetSet(mixed $key, mixed $value) {} - /** - * @param string|int $key - * @return void - */ - public function offsetUnset($key) {} + /** @return void */ + public function offsetUnset(mixed $key) {} /** @return void */ public function append(mixed $value) {} @@ -96,32 +84,28 @@ class ArrayIterator implements SeekableIterator, ArrayAccess, Serializable, Coun public function __construct(array|object $array = [], int $flags = 0) {} /** - * @param string|int $key * @return bool * @implementation-alias ArrayObject::offsetExists */ - public function offsetExists($key) {} + public function offsetExists(mixed $key) {} /** - * @param string|int $key * @return mixed * @implementation-alias ArrayObject::offsetGet */ - public function offsetGet($key) {} + public function offsetGet(mixed $key) {} /** - * @param string|int $key * @return void * @implementation-alias ArrayObject::offsetSet */ - public function offsetSet($key, mixed $value) {} + public function offsetSet(mixed $key, mixed $value) {} /** - * @param string|int $key * @return void * @implementation-alias ArrayObject::offsetUnset */ - public function offsetUnset($key) {} + public function offsetUnset(mixed $key) {} /** * @return void diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index 681547e55f71e..1249d94316371 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -211,7 +211,7 @@ public function fgetcsv(string $separator = ",", string $enclosure = "\"", strin /** @return int|false */ public function fputcsv(array $fields, string $separator = ",", string $enclosure = "\"", string $escape = "\\") {} - /** @return bool|null */ + /** @return void */ public function setCsvControl(string $separator = ",", string $enclosure = "\"", string $escape = "\\") {} /** @return array */ @@ -274,7 +274,7 @@ public function getMaxLineLen() {} /** @return bool */ public function hasChildren() {} - /** @return null */ + /** @return void */ public function getChildren() {} /** @return void */ diff --git a/ext/spl/spl_iterators.stub.php b/ext/spl/spl_iterators.stub.php index 437efec46bfb7..241b815a93499 100644 --- a/ext/spl/spl_iterators.stub.php +++ b/ext/spl/spl_iterators.stub.php @@ -53,7 +53,7 @@ public function getChildren(); class RecursiveIteratorIterator implements OuterIterator { - public function __construct(Traversable $iterator, int $mode = self::LEAVES_ONLY, int $flags = 0) {} + public function __construct(Traversable $iterator, int $mode = RecursiveIteratorIterator::LEAVES_ONLY, int $flags = 0) {} /** @return void */ public function rewind() {} @@ -200,7 +200,7 @@ public function getPosition() {} class CachingIterator extends IteratorIterator implements ArrayAccess, Countable { - public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {} + public function __construct(Iterator $iterator, int $flags = CachingIterator::CALL_TOSTRING) {} /** @return void */ public function rewind() {} @@ -255,7 +255,7 @@ public function count() {} class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator { - public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {} + public function __construct(Iterator $iterator, int $flags = RecursiveCachingIterator::CALL_TOSTRING) {} /** @return bool */ public function hasChildren() {} @@ -320,7 +320,7 @@ public function next() {} class RegexIterator extends FilterIterator { - public function __construct(Iterator $iterator, string $pattern, int $mode = self::MATCH, int $flags = 0, int $pregFlags = 0) {} + public function __construct(Iterator $iterator, string $pattern, int $mode = RegexIterator::MATCH, int $flags = 0, int $pregFlags = 0) {} /** @return bool */ public function accept() {} @@ -349,7 +349,7 @@ public function setPregFlags(int $pregFlags) {} class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator { - public function __construct(RecursiveIterator $iterator, string $pattern, int $mode = self::MATCH, int $flags = 0, int $pregFlags = 0) {} + public function __construct(RecursiveIterator $iterator, string $pattern, int $mode = RecursiveRegexIterator::MATCH, int $flags = 0, int $pregFlags = 0) {} /** @return bool */ public function accept() {} @@ -369,9 +369,9 @@ class RecursiveTreeIterator extends RecursiveIteratorIterator /** @param RecursiveIterator|IteratorAggregate $iterator */ public function __construct( $iterator, - int $flags = self::BYPASS_KEY, + int $flags = RecursiveTreeIterator::BYPASS_KEY, int $cachingIteratorFlags = CachingIterator::CATCH_GET_CHILD, - int $mode = self::SELF_FIRST + int $mode = RecursiveTreeIterator::SELF_FIRST ) {} /** @return mixed */ From ab1d0a8d9f146558f512ff418bc6b26a729c35e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 6 Jul 2021 21:35:38 +0200 Subject: [PATCH 2/2] Review fixes --- build/gen_stub.php | 11 ++++++++++- ext/spl/spl_array_arginfo.h | 6 +++--- ext/spl/spl_directory.stub.php | 6 +++--- ext/spl/spl_directory_arginfo.h | 2 +- ext/spl/spl_iterators.stub.php | 2 +- ext/spl/spl_iterators_arginfo.h | 19 +++++++++++-------- 6 files changed, 29 insertions(+), 17 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index d84851091b6c8..e288a4a7df1aa 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -118,6 +118,10 @@ public static function fromNode(Node $node): SimpleType { return new SimpleType($node->toString(), true); } + if ($node->toLowerString() === 'self') { + throw new Exception('The exact class name must be used instead of "self"'); + } + assert($node->isFullyQualified()); return new SimpleType($node->toString(), false); } @@ -142,9 +146,10 @@ public static function fromPhpDoc(string $type): SimpleType case "object": case "resource": case "mixed": - case "self": case "static": return new SimpleType(strtolower($type), true); + case "self": + throw new Exception('The exact class name must be used instead of "self"'); } if (strpos($type, "[]") !== false) { @@ -1162,6 +1167,10 @@ function parseFunctionLike( } } + if ($param->default instanceof Expr\ClassConstFetch && $param->default->class->toLowerString() === "self") { + throw new Exception('The exact class name must be used instead of "self"'); + } + $foundVariadic = $param->variadic; $args[] = new ArgInfo( diff --git a/ext/spl/spl_array_arginfo.h b/ext/spl/spl_array_arginfo.h index 46a828638e0be..5b2dcf1991f7d 100644 --- a/ext/spl/spl_array_arginfo.h +++ b/ext/spl/spl_array_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a4bc5ec5a95aae6bfa53988316cfa396f4f9fb92 */ + * Stub hash: 89f431b33667e7ee6538a2a50ed7aabcf0449d36 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0) ZEND_ARG_TYPE_MASK(0, array, MAY_BE_ARRAY|MAY_BE_OBJECT, "[]") @@ -8,13 +8,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject___construct, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject_offsetExists, 0, 0, 1) - ZEND_ARG_INFO(0, key) + ZEND_ARG_TYPE_INFO(0, key, IS_MIXED, 0) ZEND_END_ARG_INFO() #define arginfo_class_ArrayObject_offsetGet arginfo_class_ArrayObject_offsetExists ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ArrayObject_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, key) + ZEND_ARG_TYPE_INFO(0, key, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0) ZEND_END_ARG_INFO() diff --git a/ext/spl/spl_directory.stub.php b/ext/spl/spl_directory.stub.php index 1249d94316371..0b4306d95e5e5 100644 --- a/ext/spl/spl_directory.stub.php +++ b/ext/spl/spl_directory.stub.php @@ -148,7 +148,7 @@ public function rewind() {} /** @return string */ public function key() {} - /** @return string|SplFileInfo|self */ + /** @return string|SplFileInfo|FilesystemIterator */ public function current() {} /** @return int */ @@ -238,7 +238,7 @@ public function fgetc() {} /** @return int */ public function fpassthru() {} - /** @return array|int|false|null */ + /** @return array|int|null */ public function fscanf(string $format, mixed &...$vars) {} /** @return int|false */ @@ -274,7 +274,7 @@ public function getMaxLineLen() {} /** @return bool */ public function hasChildren() {} - /** @return void */ + /** @return RecursiveIterator|null */ public function getChildren() {} /** @return void */ diff --git a/ext/spl/spl_directory_arginfo.h b/ext/spl/spl_directory_arginfo.h index a16c4d45d06c8..b8f2f9528f0e2 100644 --- a/ext/spl/spl_directory_arginfo.h +++ b/ext/spl/spl_directory_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 285af54cf7b3f3ef3f0d673b248c5afbd4cc440e */ + * Stub hash: d9110bb238c9edb5c013bd482649ed96e24ff7b6 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SplFileInfo___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) diff --git a/ext/spl/spl_iterators.stub.php b/ext/spl/spl_iterators.stub.php index 241b815a93499..79ba4609c837e 100644 --- a/ext/spl/spl_iterators.stub.php +++ b/ext/spl/spl_iterators.stub.php @@ -47,7 +47,7 @@ interface RecursiveIterator extends Iterator /** @return bool */ public function hasChildren(); - /** @return RecursiveIterator */ + /** @return RecursiveIterator|null */ public function getChildren(); } diff --git a/ext/spl/spl_iterators_arginfo.h b/ext/spl/spl_iterators_arginfo.h index 999528883aa58..601dfe4d7853c 100644 --- a/ext/spl/spl_iterators_arginfo.h +++ b/ext/spl/spl_iterators_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ae7df94646bf08874d7b9804833d0081c40e0348 */ + * Stub hash: da35c3e48b3a09f5f013fdd760ddab6bdfb37967 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_EmptyIterator_current, 0, 0, 0) ZEND_END_ARG_INFO() @@ -34,7 +34,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveIteratorIterator___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::LEAVES_ONLY") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveIteratorIterator::LEAVES_ONLY") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -139,7 +139,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_CachingIterator___construct, 0, 0, 1) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "self::CALL_TOSTRING") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "CachingIterator::CALL_TOSTRING") ZEND_END_ARG_INFO() #define arginfo_class_CachingIterator_rewind arginfo_class_EmptyIterator_current @@ -176,7 +176,10 @@ ZEND_END_ARG_INFO() #define arginfo_class_CachingIterator_count arginfo_class_EmptyIterator_current -#define arginfo_class_RecursiveCachingIterator___construct arginfo_class_CachingIterator___construct +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveCachingIterator___construct, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "RecursiveCachingIterator::CALL_TOSTRING") +ZEND_END_ARG_INFO() #define arginfo_class_RecursiveCachingIterator_hasChildren arginfo_class_EmptyIterator_current @@ -217,7 +220,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RegexIterator___construct, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::MATCH") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RegexIterator::MATCH") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pregFlags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -245,7 +248,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveRegexIterator___construct, 0, 0, 2) ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::MATCH") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveRegexIterator::MATCH") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, pregFlags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -258,9 +261,9 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveTreeIterator___construct, 0, 0, 1) ZEND_ARG_INFO(0, iterator) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "self::BYPASS_KEY") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "RecursiveTreeIterator::BYPASS_KEY") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cachingIteratorFlags, IS_LONG, 0, "CachingIterator::CATCH_GET_CHILD") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "self::SELF_FIRST") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "RecursiveTreeIterator::SELF_FIRST") ZEND_END_ARG_INFO() #define arginfo_class_RecursiveTreeIterator_key arginfo_class_EmptyIterator_current