Skip to content

Commit e056e2d

Browse files
committed
Check for duplicate names in gen_stub.php
With named arguments in php 8.0, it's important that php's modules or PECL extensions using gen_stub.php don't generate functions with duplicate names. Warn if a parameter name is repeated, even if the last occurrence is a variadic parameter Closes GH-6035
1 parent 5643f34 commit e056e2d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

build/gen_stub.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ function parseFunctionLike(
646646
}
647647
}
648648

649+
$varNameSet = [];
649650
$args = [];
650651
$numRequiredArgs = 0;
651652
$foundVariadic = false;
@@ -654,6 +655,11 @@ function parseFunctionLike(
654655
$preferRef = !empty($paramMeta[$varName]['preferRef']);
655656
unset($paramMeta[$varName]);
656657

658+
if (isset($varNameSet[$varName])) {
659+
throw new Exception("Duplicate parameter name $varName for function $name");
660+
}
661+
$varNameSet[$varName] = true;
662+
657663
if ($preferRef) {
658664
$sendBy = ArgInfo::SEND_PREFER_REF;
659665
} else if ($param->byRef) {

0 commit comments

Comments
 (0)