Skip to content

Fix the default value of $ctorArgs param in PDOStatement::fetchObject() #6937

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
wants to merge 4 commits into from

Conversation

kocsismate
Copy link
Member

It looks like we don't have a real default value :(

@kocsismate kocsismate requested a review from kamil-tekiela May 4, 2021 11:49
kamil-tekiela
kamil-tekiela previously approved these changes May 4, 2021
@kocsismate
Copy link
Member Author

kocsismate commented May 4, 2021

sorry, I forgot to push my changes. Did I get it right that the behavior differs when the $ctorArgs param is provided and when it's not?

@kamil-tekiela
Copy link
Member

My first thought: I think an empty array is an acceptable compromise. We can add a note in the manual about the unexpected behaviour with the default and temporary arguments but the signature can remain as an empty array.

After thought: Can we change the code and make the parameter nullable? It looks like it was meant to be nullable. What would that take?

@kamil-tekiela kamil-tekiela dismissed their stale review May 4, 2021 12:01

New commit

@kocsismate
Copy link
Member Author

My first thought: I think an empty array is an acceptable compromise. We can add a note in the manual about the unexpected behaviour with the default and temporary arguments but the signature can remain as an empty array.

IMO the stubs need to be an authoritative source of truth. Nikita even made tests which replaces default params with the ones in the stub: #5366

After thought: Can we change the code and make the parameter nullable? It looks like it was meant to be nullable. What would that take?

we didn't do this in case of #6933 for BC, although in case of PDOStatement::fetchObject() we would have more reason.

@nikic
Copy link
Member

nikic commented May 4, 2021

I'm missing some context here, what is the reason for this change?

@kocsismate
Copy link
Member Author

kocsismate commented May 4, 2021

I've just referenced the PR where the issue came up (generating PDO methodsynopses for the doc).

@Girgias
Copy link
Member

Girgias commented May 4, 2021

IIRC all other cases which accept a constructor arguments (in the overloaded methods) accept null as a default, it might make more sense to change the implementation of the method (which is a one line change).

@nikic
Copy link
Member

nikic commented May 4, 2021

Okay, so why doesn't this simply change the implementation to make the parameter actually nullable?

@kocsismate
Copy link
Member Author

kocsismate commented May 4, 2021

Okay, so why doesn't this simply change the implementation to make the parameter actually nullable?

Due to the discussion in case of PDOStatement::fetch(), I didn't "dare" to change the signature. But I agree that it's the best course of action, and that's what I'd also prefer.

@nikic
Copy link
Member

nikic commented May 4, 2021

@kocsismate You wouldn't be changing the signature though. The signature is as declared in stubs, and that's the one that currently applies to inheriting code. There should be no BC impact from fixing the implementation.

@kocsismate
Copy link
Member Author

You wouldn't be changing the signature though. The signature is as declared in stubs, and that's the one that currently applies to inheriting code. There should be no BC impact from fixing the implementation.

oh, you are right. I'm messing up things today...

@kamil-tekiela
Copy link
Member

IIRC all other cases which accept a constructor arguments (in the overloaded methods) accept null as a default, it might make more sense to change the implementation of the method (which is a one line change).

It's more than one line of change due to the way this method is implemented. If you make it nullable you would get memory leaks as far as I can see.

@kocsismate
Copy link
Member Author

It's more than one line of change due to the way this method is implemented. If you make it nullable you would get memory leaks as far as I can see.

I'll add a test for this, and I'll work on this later.

@kocsismate kocsismate closed this in 068c8db May 5, 2021
@kocsismate kocsismate deleted the fetobject-stub branch May 5, 2021 14:54
@kamil-tekiela
Copy link
Member

@nikic Do we need to backport the memory leak fix to PHP 7.4?

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.

4 participants