Skip to content

Commit 5e73122

Browse files
committed
Add more strict verification
1 parent 295eddd commit 5e73122

13 files changed

+109
-41
lines changed

build/gen_stub.php

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
5555
initPhpParser();
5656
$fileInfo = parseStubFile($stubCode);
5757
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
58-
if ($context->forceRegeneration && file_put_contents($arginfoFile, $arginfoCode)) {
58+
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($arginfoFile, $arginfoCode)) {
5959
echo "Saved $arginfoFile\n";
6060
}
6161

@@ -64,7 +64,7 @@ function processStubFile(string $stubFile, Context $context): ?FileInfo {
6464
$funcInfo->discardInfoForOldPhpVersions();
6565
}
6666
$arginfoCode = generateArgInfoCode($fileInfo, $stubHash);
67-
if ($context->forceRegeneration === true && file_put_contents($legacyFile, $arginfoCode)) {
67+
if (($context->forceRegeneration || $stubHash !== $oldStubHash) && file_put_contents($legacyFile, $arginfoCode)) {
6868
echo "Saved $legacyFile\n";
6969
}
7070
}
@@ -360,6 +360,8 @@ public function getDeclaration(): string;
360360
public function getArgInfoName(): string;
361361
public function __toString(): string;
362362
public function isMagicMethod(): bool;
363+
public function isMethod(): bool;
364+
public function isConstructor(): bool;
363365
}
364366

365367
class FunctionName implements FunctionOrMethodName {
@@ -404,6 +406,14 @@ public function __toString(): string {
404406
public function isMagicMethod(): bool {
405407
return false;
406408
}
409+
410+
public function isMethod(): bool {
411+
return false;
412+
}
413+
414+
public function isConstructor(): bool {
415+
return false;
416+
}
407417
}
408418

409419
class MethodName implements FunctionOrMethodName {
@@ -436,6 +446,14 @@ public function __toString(): string {
436446
public function isMagicMethod(): bool {
437447
return strpos($this->methodName, '__') === 0;
438448
}
449+
450+
public function isMethod(): bool {
451+
return true;
452+
}
453+
454+
public function isConstructor(): bool {
455+
return $this->methodName === "__construct";
456+
}
439457
}
440458

441459
class ReturnInfo {
@@ -497,6 +515,11 @@ public function __construct(
497515
$this->cond = $cond;
498516
}
499517

518+
public function isInstanceMethod(): bool
519+
{
520+
return !($this->flags & Class_::MODIFIER_STATIC) && $this->name->isMethod() && $this->name->isConstructor() === false;
521+
}
522+
500523
public function equalsApartFromName(FuncInfo $other): bool {
501524
if (count($this->args) !== count($other->args)) {
502525
return false;
@@ -1325,28 +1348,66 @@ function initPhpParser() {
13251348
}
13261349
}
13271350

1328-
foreach ($aliases as $alias) {
1329-
if (!isset($funcMap[$alias->alias->__toString()])) {
1330-
$errors[] = "Aliased function {$alias->alias}() cannot be found";
1351+
foreach ($aliases as $aliasFunc) {
1352+
if (!isset($funcMap[$aliasFunc->alias->__toString()])) {
1353+
$errors[] = "Aliased function {$aliasFunc->alias}() cannot be found";
13311354
continue;
13321355
}
13331356

1334-
$aliasedFunc = $funcMap[$alias->alias->__toString()];
1357+
$aliasedFunc = $funcMap[$aliasFunc->alias->__toString()];
1358+
$aliasedArgs = $aliasedFunc->args;
1359+
$aliasArgs = $aliasFunc->args;
13351360

1336-
$aliasedArgMap = [];
1337-
foreach ($aliasedFunc->args as $arg) {
1338-
$aliasedArgMap[$arg->name] = $arg;
1339-
}
1361+
if ($aliasFunc->isInstanceMethod() !== $aliasedFunc->isInstanceMethod()) {
1362+
if ($aliasFunc->isInstanceMethod()) {
1363+
$aliasedArgs = array_slice($aliasedArgs, 1);
1364+
}
13401365

1341-
foreach ($alias->args as $arg) {
1342-
if (!isset($aliasedArgMap[$arg->name])) {
1343-
$errors[] = "{$alias->name}(): Argument \$$arg->name of aliased function {$aliasedFunc->name}() is missing";
1366+
if ($aliasedFunc->isInstanceMethod()) {
1367+
$aliasedArgs = array_slice($aliasedArgs, 1);
13441368
}
13451369
}
1370+
1371+
if ($aliasFunc->name->__toString() === "IntlCalendar::createInstance") {
1372+
var_dump($aliasArgs);
1373+
var_dump($aliasedArgs);
1374+
exit;
1375+
}
1376+
1377+
array_map(
1378+
function(?ArgInfo $aliasArg, ?ArgInfo $aliasedArg) use ($aliasFunc, $aliasedFunc, &$errors) {
1379+
if ($aliasArg === null) {
1380+
assert($aliasedArg !== null);
1381+
$errors[] = "{$aliasFunc->name}(): Argument \$$aliasedArg->name of aliased function {$aliasedFunc->name}() is missing";
1382+
return null;
1383+
}
1384+
1385+
if ($aliasedArg === null) {
1386+
assert($aliasArg !== null);
1387+
$errors[] = "{$aliasedFunc->name}(): Argument \$$aliasArg->name of alias function {$aliasFunc->name}() is missing";
1388+
return null;
1389+
}
1390+
1391+
if ($aliasArg->name !== $aliasedArg->name) {
1392+
$errors[] = "{$aliasFunc->name}(): Argument \$$aliasArg->name and argument \$$aliasedArg->name of aliased function {$aliasedFunc->name}() must have the same name";
1393+
return null;
1394+
}
1395+
1396+
if ($aliasArg->type != $aliasedArg->type) {
1397+
$errors[] = "{$aliasFunc->name}(): Argument \$$aliasArg->name and argument \$$aliasedArg->name of aliased function {$aliasedFunc->name}() must have the same type";
1398+
}
1399+
1400+
if ($aliasArg->defaultValue !== $aliasedArg->defaultValue) {
1401+
$errors[] = "{$aliasFunc->name}(): Argument \$$aliasArg->name and argument \$$aliasedArg->name of aliased function {$aliasedFunc->name}() must have the same default value";
1402+
}
1403+
},
1404+
$aliasArgs, $aliasedArgs
1405+
);
13461406
}
13471407

13481408
echo implode("\n", $errors);
13491409
if (!empty($errors)) {
1410+
echo "\n";
13501411
exit(1);
13511412
}
13521413
}

ext/date/php_date.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public function getName() {}
337337
* @return int
338338
* @alias timezone_offset_get
339339
*/
340-
public function getOffset(DateTimeInterface $object) {}
340+
public function getOffset(DateTimeInterface $datetime) {}
341341

342342
/**
343343
* @return array|false

ext/date/php_date_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 2129f4a8e4f6011ecdbda8b780d77d40512ad2d6 */
2+
* Stub hash: 04954b7aac5b3ee8e789b3ddd254ad5eda299c2b */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strtotime, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, datetime, IS_STRING, 0)
@@ -368,7 +368,7 @@ ZEND_END_ARG_INFO()
368368
#define arginfo_class_DateTimeZone_getName arginfo_class_DateTimeInterface_getTimezone
369369

370370
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTimeZone_getOffset, 0, 0, 1)
371-
ZEND_ARG_OBJ_INFO(0, object, DateTimeInterface, 0)
371+
ZEND_ARG_OBJ_INFO(0, datetime, DateTimeInterface, 0)
372372
ZEND_END_ARG_INFO()
373373

374374
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DateTimeZone_getTransitions, 0, 0, 0)

ext/intl/calendar/calendar.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private function __construct() {}
99
/**
1010
* @param IntlTimeZone|DateTimeZone|string|null $timezone
1111
* @return IntlCalendar|IntlGregorianCalendar|null
12-
* @alias intlcal_create_instance
12+
* @implementation-alias intlcal_create_instance
1313
*/
1414
public static function createInstance($timezone = null, ?string $locale = null) {}
1515

@@ -51,7 +51,7 @@ public function clear(?int $field = null) {}
5151

5252
/**
5353
* @return IntlCalendar|null
54-
* @alias intlcal_from_date_time
54+
* @implementation-alias intlcal_from_date_time
5555
*/
5656
public static function fromDateTime(DateTime|string $datetime, ?string $locale = null) {}
5757

ext/intl/calendar/calendar_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: ee755d4a500e2d1ba4d589c233b7d09a06b5cce8 */
2+
* Stub hash: ed58347be3b240d64bba9fcf6587d26d338c7fa3 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()

ext/mysqli/mysqli.stub.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function commit(int $flags = -1, ?string $name = null) {}
5757
* @return mysqli|null|false
5858
* @alias mysqli_connect
5959
*/
60-
public function connect(
61-
?string $host = null,
60+
public static function connect(
61+
?string $hostname = null,
6262
?string $username = null,
6363
?string $password = null,
6464
?string $database = null,
@@ -76,7 +76,7 @@ public function dump_debug_info() {}
7676
* @return bool
7777
* @alias mysqli_debug
7878
*/
79-
public function debug(string $message) {}
79+
public static function debug(string $options) {}
8080

8181
/**
8282
* @return object|null
@@ -534,7 +534,7 @@ function mysqli_close(mysqli $mysql): bool {}
534534
function mysqli_commit(mysqli $mysql, int $flags = -1, ?string $name = null): bool {}
535535

536536
function mysqli_connect(
537-
?string $host = null,
537+
?string $hostname = null,
538538
?string $username = null,
539539
?string $password = null,
540540
?string $database = null,
@@ -550,7 +550,7 @@ function mysqli_data_seek(mysqli_result $result, int $offset): bool {}
550550

551551
function mysqli_dump_debug_info(mysqli $mysql): bool {}
552552

553-
function mysqli_debug(string $message): bool {}
553+
function mysqli_debug(string $options): bool {}
554554

555555
function mysqli_errno(mysqli $mysql): int {}
556556

ext/mysqli/mysqli_arginfo.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 0c4478112ac85b80838c47eee6ff726319edae49 */
2+
* Stub hash: 7c1efd15808391426e88356efab92d9acedebc49 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mysqli_affected_rows, 0, 1, MAY_BE_LONG|MAY_BE_STRING)
55
ZEND_ARG_OBJ_INFO(0, mysql, mysqli, 0)
@@ -38,7 +38,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_commit, 0, 1, _IS_BOOL, 0
3838
ZEND_END_ARG_INFO()
3939

4040
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_mysqli_connect, 0, 0, mysqli, MAY_BE_NULL|MAY_BE_FALSE)
41-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, host, IS_STRING, 1, "null")
41+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, hostname, IS_STRING, 1, "null")
4242
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, username, IS_STRING, 1, "null")
4343
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
4444
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, database, IS_STRING, 1, "null")
@@ -60,7 +60,7 @@ ZEND_END_ARG_INFO()
6060
#define arginfo_mysqli_dump_debug_info arginfo_mysqli_close
6161

6262
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_debug, 0, 1, _IS_BOOL, 0)
63-
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
63+
ZEND_ARG_TYPE_INFO(0, options, IS_STRING, 0)
6464
ZEND_END_ARG_INFO()
6565

6666
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_errno, 0, 1, IS_LONG, 0)
@@ -456,12 +456,19 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_commit, 0, 0, 0)
456456
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, name, IS_STRING, 1, "null")
457457
ZEND_END_ARG_INFO()
458458

459-
#define arginfo_class_mysqli_connect arginfo_class_mysqli___construct
459+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_connect, 0, 0, 0)
460+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, hostname, IS_STRING, 1, "null")
461+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, username, IS_STRING, 1, "null")
462+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
463+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, database, IS_STRING, 1, "null")
464+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, port, IS_LONG, 1, "null")
465+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, socket, IS_STRING, 1, "null")
466+
ZEND_END_ARG_INFO()
460467

461468
#define arginfo_class_mysqli_dump_debug_info arginfo_class_mysqli_character_set_name
462469

463470
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_debug, 0, 0, 1)
464-
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
471+
ZEND_ARG_TYPE_INFO(0, options, IS_STRING, 0)
465472
ZEND_END_ARG_INFO()
466473

467474
#define arginfo_class_mysqli_get_charset arginfo_class_mysqli_character_set_name
@@ -957,9 +964,9 @@ static const zend_function_entry class_mysqli_methods[] = {
957964
ZEND_ME_MAPPING(character_set_name, mysqli_character_set_name, arginfo_class_mysqli_character_set_name, ZEND_ACC_PUBLIC)
958965
ZEND_ME_MAPPING(close, mysqli_close, arginfo_class_mysqli_close, ZEND_ACC_PUBLIC)
959966
ZEND_ME_MAPPING(commit, mysqli_commit, arginfo_class_mysqli_commit, ZEND_ACC_PUBLIC)
960-
ZEND_ME_MAPPING(connect, mysqli_connect, arginfo_class_mysqli_connect, ZEND_ACC_PUBLIC)
967+
ZEND_ME_MAPPING(connect, mysqli_connect, arginfo_class_mysqli_connect, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
961968
ZEND_ME_MAPPING(dump_debug_info, mysqli_dump_debug_info, arginfo_class_mysqli_dump_debug_info, ZEND_ACC_PUBLIC)
962-
ZEND_ME_MAPPING(debug, mysqli_debug, arginfo_class_mysqli_debug, ZEND_ACC_PUBLIC)
969+
ZEND_ME_MAPPING(debug, mysqli_debug, arginfo_class_mysqli_debug, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
963970
ZEND_ME_MAPPING(get_charset, mysqli_get_charset, arginfo_class_mysqli_get_charset, ZEND_ACC_PUBLIC)
964971
ZEND_ME_MAPPING(get_client_info, mysqli_get_client_info, arginfo_class_mysqli_get_client_info, ZEND_ACC_PUBLIC)
965972
#if defined(MYSQLI_USE_MYSQLND)

ext/tidy/tidy.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public function parseString(string $string, array|string|null $config = null, ?s
7878
* @return bool
7979
* @alias tidy_repair_string
8080
*/
81-
public function repairString(string $string, array|string|null $config = null, ?string $encoding = null) {}
81+
public static function repairString(string $string, array|string|null $config = null, ?string $encoding = null) {}
8282

8383
/**
8484
* @return bool
8585
* @alias tidy_repair_file
8686
*/
87-
public function repairFile(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {}
87+
public static function repairFile(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {}
8888

8989
/**
9090
* @return bool

ext/tidy/tidy_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: ac4cd960d6c65653994b8b044dcc52c179a57d45 */
2+
* Stub hash: 4042c33d3ea3f5fb87cfb696488f6280b6ec7e7f */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_tidy_parse_string, 0, 1, tidy, MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
@@ -248,8 +248,8 @@ static const zend_function_entry class_tidy_methods[] = {
248248
ZEND_ME_MAPPING(cleanRepair, tidy_clean_repair, arginfo_class_tidy_cleanRepair, ZEND_ACC_PUBLIC)
249249
ZEND_ME(tidy, parseFile, arginfo_class_tidy_parseFile, ZEND_ACC_PUBLIC)
250250
ZEND_ME(tidy, parseString, arginfo_class_tidy_parseString, ZEND_ACC_PUBLIC)
251-
ZEND_ME_MAPPING(repairString, tidy_repair_string, arginfo_class_tidy_repairString, ZEND_ACC_PUBLIC)
252-
ZEND_ME_MAPPING(repairFile, tidy_repair_file, arginfo_class_tidy_repairFile, ZEND_ACC_PUBLIC)
251+
ZEND_ME_MAPPING(repairString, tidy_repair_string, arginfo_class_tidy_repairString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
252+
ZEND_ME_MAPPING(repairFile, tidy_repair_file, arginfo_class_tidy_repairFile, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
253253
ZEND_ME_MAPPING(diagnose, tidy_diagnose, arginfo_class_tidy_diagnose, ZEND_ACC_PUBLIC)
254254
ZEND_ME_MAPPING(getRelease, tidy_get_release, arginfo_class_tidy_getRelease, ZEND_ACC_PUBLIC)
255255
ZEND_ME_MAPPING(getConfig, tidy_get_config, arginfo_class_tidy_getConfig, ZEND_ACC_PUBLIC)

ext/xmlwriter/php_xmlwriter.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class XMLWriter
9292
* @return bool
9393
* @alias xmlwriter_open_uri
9494
*/
95-
public function openUri(string $uri) {}
95+
public static function openUri(string $uri) {}
9696

9797
/**
9898
* @return bool

ext/xmlwriter/php_xmlwriter_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: df2a62a48636bd2c7b1e62ac28480ae27233f100 */
2+
* Stub hash: 1dac866f8b92d14862818a3350cc4f902c35dc65 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xmlwriter_open_uri, 0, 1, XMLWriter, MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, uri, IS_STRING, 0)
@@ -420,7 +420,7 @@ static const zend_function_entry ext_functions[] = {
420420

421421

422422
static const zend_function_entry class_XMLWriter_methods[] = {
423-
ZEND_ME_MAPPING(openUri, xmlwriter_open_uri, arginfo_class_XMLWriter_openUri, ZEND_ACC_PUBLIC)
423+
ZEND_ME_MAPPING(openUri, xmlwriter_open_uri, arginfo_class_XMLWriter_openUri, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
424424
ZEND_ME_MAPPING(openMemory, xmlwriter_open_memory, arginfo_class_XMLWriter_openMemory, ZEND_ACC_PUBLIC)
425425
ZEND_ME_MAPPING(setIndent, xmlwriter_set_indent, arginfo_class_XMLWriter_setIndent, ZEND_ACC_PUBLIC)
426426
ZEND_ME_MAPPING(setIndentString, xmlwriter_set_indent_string, arginfo_class_XMLWriter_setIndentString, ZEND_ACC_PUBLIC)

ext/zlib/zlib.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function gzread($stream, int $length): string|false {}
9999

100100
/**
101101
* @param resource $stream
102-
* @alias fgets
102+
* @implementation-alias fgets
103103
*/
104104
function gzgets($stream, int $length = 1024): string|false {}
105105

ext/zlib/zlib_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 4106a50d3930915e47548be72f984420c5af6149 */
2+
* Stub hash: 940858ddc4ddc7edb1e00960334ffa473224fd85 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_ob_gzhandler, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)

0 commit comments

Comments
 (0)