Skip to content

Fix the built-in function examples for ReflectionFunctionAbstract return types - #6217

Open
cookieguru wants to merge 2 commits into
php:masterfrom
cookieguru:fix-reflection-return-type-examples
Open

cookieguru wants to merge 2 commits into
php:masterfrom
cookieguru:fix-reflection-return-type-examples

Conversation

@cookieguru

Copy link
Copy Markdown
Contributor

The "Usage on built-in functions" examples for ReflectionFunctionAbstract::getReturnType() and hasReturnType() use array_merge(), which has declared an array return type since PHP 8.0.0, so they no longer print null and bool(false).

Update the examples to use fopen() instead. It returns a resource, which can't be declared, so both methods report no return type for it on every release from PHP 7.0.0 to 8.6.0. The note under getReturnType() no longer says that many internal functions lack types.

In addition, the getReturnType() output is now NULL, as var_dump() prints it.

In the PHP-8.6 stubs, 17 functions declare no return type (this number excludes extensions), and 15 of them return a resource. The others are set_error_handler() and set_exception_handler().

array_merge() declares an array return type as of PHP 8.0.0, so
getReturnType() and hasReturnType() no longer print null and false for
it.  fopen() returns a resource, which cannot be declared, so it has no
return type on any version.  Reword the getReturnType() note to match.
var_dump() prints NULL in capitals, so the documented lowercase null
never matched what the example prints.
@cookieguru
cookieguru force-pushed the fix-reflection-return-type-examples branch from 4fce308 to 848a204 Compare December 3, 2026 23:30
@cookieguru

Copy link
Copy Markdown
Contributor Author

I think it may be OK to remove "It is therefore best to avoid using this method on built-in functions" but I will wait for the advice of a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant