Skip to content

Add a few types to zend_builtin_functions stub #13636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

alexandre-daubois
Copy link
Contributor

@alexandre-daubois alexandre-daubois commented Mar 8, 2024

Inspired by #13614, it seems we can add these return types to stubs?

@@ -65,14 +65,12 @@ function get_mangled_object_vars(object $object): array {}
*/
function get_class_methods(object|string $object_or_class): array {}

/** @param object|string $object_or_class */
function method_exists($object_or_class, string $method): bool {}
function method_exists(object|string $object_or_class, string $method): bool {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were multiple attempts to add these param types but at last we settled on not to add them. See
#11555 (comment) for reasoning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, got it 👍

@@ -107,13 +105,11 @@ function trigger_error(string $message, int $error_level = E_USER_NOTICE): true
/** @alias trigger_error */
function user_error(string $message, int $error_level = E_USER_NOTICE): true {}

/** @return callable|null */
function set_error_handler(?callable $callback, int $error_levels = E_ALL) {}
function set_error_handler(?callable $callback, int $error_levels = E_ALL): ?callable {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason these return types are not documented is described in Nikita's comment: #5618 (review)

@kocsismate kocsismate requested a review from Girgias March 10, 2024 21:27
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically as @kocsismate has already indicated from prior discussion it is not really doable.

However, for set_error_handler/set_exception_handler I can imagine that if we return a Closure instead of just a callable that would solve the scoping issue that Nikita mentioned. But this might break some userland expectations?

@alexandre-daubois
Copy link
Contributor Author

There's no broken expectation I can see. What could be done in userland is either use is_callable, or invoke the return value which would both work with Closure. So I think this may work unless I miss a use case

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

Successfully merging this pull request may close these issues.

3 participants