diff --git a/src/Translator.php b/src/Translator.php index d3426cc3..177cd755 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -898,11 +898,11 @@ CODE; } $fullName = $functionDef->getNamespacedName(); $zifName = $this->escapeZendFnName($fullName); - if ($functionDef->namespace) { - $code .= $this->getIndent() . 'ZEND_NAMED_FE("' . $this->escapeString($fullName) . '", ZEND_FN(' . $zifName . '), arginfo_' . $zifName . ')' . PHP_EOL; - } else { - $code .= $this->getIndent() . 'ZEND_FE(' . $zifName . ', arginfo_' . $zifName . ')' . PHP_EOL; - } + // TypePHP is always strict. Store the flag in the registered + // zend_function instead of rewriting shared metadata on every call. + $code .= $this->getIndent() . 'ZEND_RAW_FENTRY("' . $this->escapeString($fullName) + . '", ZEND_FN(' . $zifName . '), arginfo_' . $zifName + . ', ZEND_ACC_STRICT_TYPES, NULL, NULL)' . PHP_EOL; } $code .= $this->getIndent() . "ZEND_FE_END\n};\n// clang-format on" . PHP_EOL . PHP_EOL; @@ -3246,6 +3246,7 @@ CODE; if ($functionDef->argCountRequired > 0) { $cppCode .= $this->genWrapperRequiredArgCountCheck($functionDef, $displayName); } + foreach ($functionDef->argInfoList as $k => $argInfo) { $var = 'arg_' . $argInfo->name; if ($argInfo->variadic) { @@ -4981,4 +4982,5 @@ CODE; return $code; } + } diff --git a/src/gen_stub.php b/src/gen_stub.php index 779d39c8..51d9a8b2 100755 --- a/src/gen_stub.php +++ b/src/gen_stub.php @@ -1688,7 +1688,9 @@ class FuncInfo { private function getArginfoFlagsByPhpVersions(): VersionFlags { - $flags = []; + // TypePHP is always strict. Register functions and methods with the + // flag once so dynamic calls made by native bodies inherit that mode. + $flags = ["ZEND_ACC_STRICT_TYPES"]; if ($this->isMethod()) { if ($this->flags & Modifiers::PROTECTED) { diff --git a/tests/compiler/declare/strict_types-default.phpt b/tests/compiler/declare/strict_types-default.phpt new file mode 100644 index 00000000..a14b9410 --- /dev/null +++ b/tests/compiler/declare/strict_types-default.phpt @@ -0,0 +1,38 @@ +--TEST-- +TypePHP enables strict types without a declare directive +--FILE-- + +--EXPECT-- +main=TypeError +function=TypeError +method=TypeError diff --git a/tests/compiler/declare/strict_types.phpt b/tests/compiler/declare/strict_types.phpt new file mode 100644 index 00000000..120d14cc --- /dev/null +++ b/tests/compiler/declare/strict_types.phpt @@ -0,0 +1,17 @@ +--TEST-- +declare: strict types 1 +--FILE-- + +--EXPECT-- +TypeError