]> granicus.if.org Git - php/commitdiff
Check for duplicate names in gen_stub.php
authorTyson Andre <tysonandre775@hotmail.com>
Sun, 23 Aug 2020 14:46:40 +0000 (10:46 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Mon, 24 Aug 2020 13:31:46 +0000 (09:31 -0400)
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

build/gen_stub.php

index fb79255e849487caf6bce4c7f389663c2856a565..214d1f563e737727aee315310f006477b7c19e78 100755 (executable)
@@ -646,6 +646,7 @@ function parseFunctionLike(
         }
     }
 
+    $varNameSet = [];
     $args = [];
     $numRequiredArgs = 0;
     $foundVariadic = false;
@@ -654,6 +655,11 @@ function parseFunctionLike(
         $preferRef = !empty($paramMeta[$varName]['preferRef']);
         unset($paramMeta[$varName]);
 
+        if (isset($varNameSet[$varName])) {
+            throw new Exception("Duplicate parameter name $varName for function $name");
+        }
+        $varNameSet[$varName] = true;
+
         if ($preferRef) {
             $sendBy = ArgInfo::SEND_PREFER_REF;
         } else if ($param->byRef) {