diff --git a/build/gen_stub.php b/build/gen_stub.php index 806a8fa35de06..166c61ca2b916 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -3763,12 +3763,16 @@ protected function pName_FullyQualified(Name\FullyQualified $node) { return $fileInfo; } -function funcInfoToCode(FuncInfo $funcInfo): string { +function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string { $code = ''; $returnType = $funcInfo->return->type; $isTentativeReturnType = $funcInfo->return->tentativeReturnType; + $php81MinimumCompatibility = $fileInfo->generateLegacyArginfoForPhpVersionId === null || $fileInfo->generateLegacyArginfoForPhpVersionId >= PHP_81_VERSION_ID; if ($returnType !== null) { + if ($isTentativeReturnType && !$php81MinimumCompatibility) { + $code .= "#if (PHP_VERSION_ID >= " . PHP_81_VERSION_ID . ")\n"; + } if (null !== $simpleReturnType = $returnType->tryToSimpleType()) { if ($simpleReturnType->isBuiltin) { $code .= sprintf( @@ -3807,6 +3811,12 @@ function funcInfoToCode(FuncInfo $funcInfo): string { ); } } + if ($isTentativeReturnType && !$php81MinimumCompatibility) { + $code .= sprintf( + "#else\nZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)\n#endif\n", + $funcInfo->getArgInfoName(), $funcInfo->return->byRef, $funcInfo->numRequiredArgs + ); + } } else { $code .= sprintf( "ZEND_BEGIN_ARG_INFO_EX(%s, 0, %d, %d)\n", @@ -3919,7 +3929,7 @@ function generateArgInfoCode( $generatedFuncInfos = []; $code .= generateCodeWithConditions( $fileInfo->getAllFuncInfos(), "\n", - static function (FuncInfo $funcInfo) use (&$generatedFuncInfos) { + static function (FuncInfo $funcInfo) use (&$generatedFuncInfos, $fileInfo) { /* If there already is an equivalent arginfo structure, only emit a #define */ if ($generatedFuncInfo = findEquivalentFuncInfo($generatedFuncInfos, $funcInfo)) { $code = sprintf( @@ -3927,7 +3937,7 @@ static function (FuncInfo $funcInfo) use (&$generatedFuncInfos) { $funcInfo->getArgInfoName(), $generatedFuncInfo->getArgInfoName() ); } else { - $code = funcInfoToCode($funcInfo); + $code = funcInfoToCode($fileInfo, $funcInfo); } $generatedFuncInfos[] = $funcInfo; diff --git a/ext/zend_test/test.c b/ext/zend_test/test.c index 14dcfef98f5ad..71190da88942b 100644 --- a/ext/zend_test/test.c +++ b/ext/zend_test/test.c @@ -531,6 +531,8 @@ static ZEND_METHOD(_ZendTestTrait, testMethod) static ZEND_METHOD(ZendTestNS_Foo, method) { ZEND_PARSE_PARAMETERS_NONE(); + + RETURN_LONG(0); } static ZEND_METHOD(ZendTestNS2_Foo, method) diff --git a/ext/zend_test/test.stub.php b/ext/zend_test/test.stub.php index b99a28ea82501..64b4f65648be7 100644 --- a/ext/zend_test/test.stub.php +++ b/ext/zend_test/test.stub.php @@ -1,7 +1,9 @@ = 80100) +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ZendTestNS_Foo_method, 0, 0, IS_LONG, 0) +#else +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZendTestNS_Foo_method, 0, 0, 0) +#endif +ZEND_END_ARG_INFO() #define arginfo_class_ZendTestNS2_Foo_method arginfo_zend_test_void_return @@ -350,7 +355,11 @@ static zend_class_entry *register_class__ZendTestClass(zend_class_entry *class_e zval property_readonlyProp_default_value; ZVAL_UNDEF(&property_readonlyProp_default_value); zend_string *property_readonlyProp_name = zend_string_init("readonlyProp", sizeof("readonlyProp") - 1, 1); +#if (PHP_VERSION_ID >= 80100) zend_declare_typed_property(class_entry, property_readonlyProp_name, &property_readonlyProp_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); +#elif (PHP_VERSION_ID >= 80000) + zend_declare_typed_property(class_entry, property_readonlyProp_name, &property_readonlyProp_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); +#endif zend_string_release(property_readonlyProp_name); return class_entry; @@ -391,12 +400,14 @@ static zend_class_entry *register_class_ZendTestAttribute(void) class_entry = zend_register_internal_class_ex(&ce, NULL); class_entry->ce_flags |= ZEND_ACC_FINAL; +#if (PHP_VERSION_ID >= 80200) zend_string *attribute_name_Attribute_class_ZendTestAttribute = zend_string_init("Attribute", sizeof("Attribute") - 1, 1); zend_attribute *attribute_Attribute_class_ZendTestAttribute = zend_add_class_attribute(class_entry, attribute_name_Attribute_class_ZendTestAttribute, 1); zend_string_release(attribute_name_Attribute_class_ZendTestAttribute); zval attribute_Attribute_class_ZendTestAttribute_arg0; ZVAL_LONG(&attribute_Attribute_class_ZendTestAttribute_arg0, ZEND_ATTRIBUTE_TARGET_ALL); ZVAL_COPY_VALUE(&attribute_Attribute_class_ZendTestAttribute->args[0].value, &attribute_Attribute_class_ZendTestAttribute_arg0); +#endif return class_entry; } @@ -415,12 +426,14 @@ static zend_class_entry *register_class_ZendTestParameterAttribute(void) zend_declare_typed_property(class_entry, property_parameter_name, &property_parameter_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING)); zend_string_release(property_parameter_name); +#if (PHP_VERSION_ID >= 80200) zend_string *attribute_name_Attribute_class_ZendTestParameterAttribute = zend_string_init("Attribute", sizeof("Attribute") - 1, 1); zend_attribute *attribute_Attribute_class_ZendTestParameterAttribute = zend_add_class_attribute(class_entry, attribute_name_Attribute_class_ZendTestParameterAttribute, 1); zend_string_release(attribute_name_Attribute_class_ZendTestParameterAttribute); zval attribute_Attribute_class_ZendTestParameterAttribute_arg0; ZVAL_LONG(&attribute_Attribute_class_ZendTestParameterAttribute_arg0, ZEND_ATTRIBUTE_TARGET_PARAMETER); ZVAL_COPY_VALUE(&attribute_Attribute_class_ZendTestParameterAttribute->args[0].value, &attribute_Attribute_class_ZendTestParameterAttribute_arg0); +#endif return class_entry; } @@ -456,6 +469,7 @@ static zend_class_entry *register_class_ZendTestForbidDynamicCall(void) return class_entry; } +#if (PHP_VERSION_ID >= 80100) static zend_class_entry *register_class_ZendTestUnitEnum(void) { zend_class_entry *class_entry = zend_register_internal_enum("ZendTestUnitEnum", IS_UNDEF, class_ZendTestUnitEnum_methods); @@ -466,7 +480,9 @@ static zend_class_entry *register_class_ZendTestUnitEnum(void) return class_entry; } +#endif +#if (PHP_VERSION_ID >= 80100) static zend_class_entry *register_class_ZendTestStringEnum(void) { zend_class_entry *class_entry = zend_register_internal_enum("ZendTestStringEnum", IS_STRING, class_ZendTestStringEnum_methods); @@ -493,7 +509,9 @@ static zend_class_entry *register_class_ZendTestStringEnum(void) return class_entry; } +#endif +#if (PHP_VERSION_ID >= 80100) static zend_class_entry *register_class_ZendTestIntEnum(void) { zend_class_entry *class_entry = zend_register_internal_enum("ZendTestIntEnum", IS_LONG, class_ZendTestIntEnum_methods); @@ -512,6 +530,7 @@ static zend_class_entry *register_class_ZendTestIntEnum(void) return class_entry; } +#endif static zend_class_entry *register_class_ZendTestNS_Foo(void) {