Skip to content

Cleanup argument handling in ext/reflection #5850

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

kocsismate
Copy link
Member

  • Renamed a few arguments
  • Converted a few PHPDoc types to type delcarations
  • Added necessary macros for ZPP

ZEND_PARSE_PARAMETERS_END();

if (closure_obj) {
fptr = (zend_function*)zend_get_closure_method_def_from_obj(closure_obj);
} else {
ALLOCA_FLAG(use_heap)
Copy link
Member Author

@kocsismate kocsismate Jul 13, 2020

Choose a reason for hiding this comment

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

I don't know what ALLOCA_FLAG does :/ But I have a suspicion that it was intentionally used only for the string parameter.

Copy link
Member

@nikic nikic Jul 24, 2020

Choose a reason for hiding this comment

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

You can move it into the branch doing the ZSTR_ALLOCA_ALLOC (to be more obvious).

@kocsismate kocsismate marked this pull request as draft July 13, 2020 08:26
@kocsismate kocsismate force-pushed the argument-handling-reflection branch from e795a78 to bb2baaa Compare July 14, 2020 09:31
@kocsismate kocsismate marked this pull request as ready for review July 14, 2020 09:47
@kocsismate kocsismate force-pushed the argument-handling-reflection branch from bb2baaa to 1bb4364 Compare July 14, 2020 10:02
/** @param object|string $class_or_method */
public function __construct($class_or_method, string $name = UNKNOWN) {}
/** @param object|string $objectOrMethodName */
public function __construct($objectOrMethodName, string $methodName = UNKNOWN) {}
Copy link
Member Author

Choose a reason for hiding this comment

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

The behaviour of $objectOrMethodName seems a bit crazy to me (it accepts either an object or a method name in the Object::method format). Should we deprecate it in the PHP 8.1 deprecations? And we could add a static ReflectionMethod::fromMethodName(string $methodName) method as a replacement. ping @Girgias @nikic

Copy link
Member

Choose a reason for hiding this comment

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

That one seems pretty whack indeed, I think having the replacement method in PHP 8.0 would be ideal so that we can deprecate it in 8.1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, exactly my thoughts too! I can provide it in a separate PR if it doesn't need any kind of "bureaucracy" ^^

@kocsismate kocsismate force-pushed the argument-handling-reflection branch from 1bb4364 to 72e1525 Compare July 14, 2020 11:10
@kocsismate kocsismate force-pushed the argument-handling-reflection branch from 72e1525 to fb65dbe Compare July 21, 2020 17:16
@nikic
Copy link
Member

nikic commented Jul 23, 2020

Same as in zend_builtin_functions.c, I'm not really convinced about treating class names as a weak string parameter. Do you think we could get away with using CLASS_NAME_OR_OBJ, with the corresponding change in exception type?

@kocsismate
Copy link
Member Author

Same as in zend_builtin_functions.c, I'm not really convinced about treating class names as a weak string parameter. Do you think we could get away with using CLASS_NAME_OR_OBJ, with the corresponding change in exception type?

The reason why I reverted those changes is that we can't express at the type system's level, that a valid, autoloadable class is expected, so throwing a TypeError for not found classes seems unfair for me. Especially, because people used to face a ReflectionException before, in this case. After my changes, they would get a TypeError for arguments not satisfying the method signature, and a ReflectionException if the class name is somehow not right.

But please correct me if you spot any issue with this reasoning. :)

@kocsismate kocsismate force-pushed the argument-handling-reflection branch from fb65dbe to 4096327 Compare July 24, 2020 11:51
ZEND_PARSE_PARAMETERS_END();

if (closure_obj) {
fptr = (zend_function*)zend_get_closure_method_def_from_obj(closure_obj);
} else {
ALLOCA_FLAG(use_heap)
Copy link
Member

@nikic nikic Jul 24, 2020

Choose a reason for hiding this comment

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

You can move it into the branch doing the ZSTR_ALLOCA_ALLOC (to be more obvious).

@nikic
Copy link
Member

nikic commented Jul 24, 2020

Same as in zend_builtin_functions.c, I'm not really convinced about treating class names as a weak string parameter. Do you think we could get away with using CLASS_NAME_OR_OBJ, with the corresponding change in exception type?

The reason why I reverted those changes is that we can't express at the type system's level, that a valid, autoloadable class is expected, so throwing a TypeError for not found classes seems unfair for me. Especially, because people used to face a ReflectionException before, in this case. After my changes, they would get a TypeError for arguments not satisfying the method signature, and a ReflectionException if the class name is somehow not right.

But please correct me if you spot any issue with this reasoning. :)

Fair enough. I guess it's safer to keep the ReflectionException. And as non-string will always throw anyway ("" and "1" are not valid classes...), it's not too bad to accept weakly.

@kocsismate kocsismate force-pushed the argument-handling-reflection branch from 4096327 to 5759fbf Compare July 24, 2020 14:56
@php-pulls php-pulls closed this in 8664ff7 Jul 24, 2020
@kocsismate kocsismate deleted the argument-handling-reflection branch July 24, 2020 16:07
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.

4 participants