Skip to content

Implement "Deprecate functions with overloaded signatures" RFC for PHP 8.3 #11703

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

Merged
merged 13 commits into from
Jul 18, 2023

Conversation

kocsismate
Copy link
Member

@iluuu1994
Copy link
Member

I did not review this yet, but the PR is missing checks for exceptions promoted by error handlers after zend_error(E_DEPRECATED, ...).

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.

I made a first pass with some comments, I skipped FFI and Date, but the other ones mostly seem to make sense.

ext/dba/dba.c Outdated
Comment on lines 970 to 971
zend_error(E_DEPRECATED, "Calling dba_fetch() with $dba at the 3rd parameter is deprecated",
ZSTR_VAL(fbc->common.function_name));
Copy link
Member

Choose a reason for hiding this comment

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

Passing that char* seems odd?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, there used to be a %s instead of dba_fetch(), and I forgot to remove the parameter.

@kocsismate
Copy link
Member Author

I squashed the fixups because there were too many of them. Sorry for that!

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.

I am fine with already merging the DBA, Intl, Reflection, Phar, PGSQL, and stream PRs.

FFI and get_class() has legit CI failures.

@Girgias
Copy link
Member

Girgias commented Jul 16, 2023

Actually the intl and postgress also have CI failures on Windows.

@kocsismate
Copy link
Member Author

Actually the intl and postgress also have CI failures on Windows.

Thanks for the reminder, I've just tried to fixed them. Turned out that I had a bug in the pgsql code...

I'll also try to fix the FFI memleaks tomorrow. Unfortunately, I cannot reproduce them locally, but at least I have a suspecicion where the issue lies.

@Girgias
Copy link
Member

Girgias commented Jul 16, 2023

I can reproduce the FFI failures with ASAN, and the memory leak is a pre-existing issue, which I assume is related to something not being cleaned-up on failure when the FFI object is being destroyed.

To not have this be blocking, either XFAIL this or revert the 3 tests to use the static method and emit the deprecation notice.

@dstogov (or @bwoebi) I'm imagining the issues is related to the FFI destructors not properly cleaning up after themselves if not called statically. The fix should also be backported to supported versions.

@kocsismate
Copy link
Member Author

I can reproduce the FFI failures with ASAN, and the memory leak is a pre-existing issue, which I assume is related to something not being cleaned-up on failure when the FFI object is being destroyed.

Relevant test PR: #11720

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

To clarify: It is common for PHP code to register error handlers that promote errors to exceptions. In these cases, the called functions shouldn't actually take effect, i.e. execute, so we need to abort accordingly with `if (UNEXPECTED(EG(exception)) { possibly_cleanup(); RETURN_THROWS(); }

if (UNEXPECTED(EG(exception))) {
HANDLE_EXCEPTION();
} else {
ZEND_VM_NEXT_OPCODE();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: No need to move this line.

ext/ldap/ldap.c Outdated
char *wallet = NULL, *walletpasswd = NULL;
size_t walletlen = 0, walletpasswdlen = 0;
zend_long authmode = GSLC_SSL_NO_AUTH;
int ssl = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Could be a bool.

@kocsismate
Copy link
Member Author

I'm merging this PR so that it safely meets the feature freeze deadline. I'm going to fix any issues coming up in followups.

@kocsismate kocsismate merged commit a5ad7e0 into php:master Jul 18, 2023
@kocsismate kocsismate deleted the overridden-funcs branch July 18, 2023 10:59
@@ -205,6 +205,8 @@ class ReflectionMethod extends ReflectionFunctionAbstract

public function __construct(object|string $objectOrMethod, ?string $method = null) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

According to RFC the last argument should be required

Copy link
Contributor

@andypost andypost Jul 19, 2023

Choose a reason for hiding this comment

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

Is there follow-up for that? or passing one argument will remain til 8.4 as freeze in action?
https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#reflectionmethodconstruct

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 RFC lists the last parameter as required only in one of the signatures, but since there is another one with 1 parameter, the stub - which unified the two signatures - displays the 2nd parameter as optional.

Is there follow-up for that?

What kind of follow-up do you mean? According to the RFC, the signatures and the behavior of ReflectionMethod::__construct() won't change until 9.0, except for the signature with 1 parameter will be deprecated in PHP 8.4. In 9.0, the constructor will only accept 2 arguments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you! misread

deprecate the second constructor signature in PHP 8.4

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Jul 23, 2023

Hello, this introduced:

ErrorException: Calling ReflectionProperty::setValue() with a single argument is deprecated

But no alternative is given, and documentation still promote this way to set static properties:
https://www.php.net/manual/en/reflectionproperty.setvalue.php

So what to do in this particular case, and more generally, how do you expect developers to find out the fixes when hitting those kind of deprecations?

[EDIT]

Found setStaticPropertyValue, I'm testing now if it does the job. Sound like a documentation update is needed to replace the ->getProperty('foo')->setValue('bar') examples.

@kocsismate
Copy link
Member Author

Hi @kylekatarnls ,

Thanks for the investigation! The RFC suggests another alternative: the the relevant section in https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures

@Girgias
Copy link
Member

Girgias commented Jul 24, 2023

But no alternative is given, and documentation still promote this way to set static properties: https://www.php.net/manual/en/reflectionproperty.setvalue.php

So what to do in this particular case, and more generally, how do you expect developers to find out the fixes when hitting those kind of deprecations?

Migrations strategies will be written as part of the migration docs which are yet to be written.

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.

6 participants