Skip to content
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

Replaced func_get_args() with variadic arguments #3831

Merged
merged 1 commit into from
Jan 21, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented Jan 18, 2020

Q A
Type improvement
BC Break yes

Fixes #3825

In addition to the method signature changes, the following changes have been made:

  1. The implementations of where(), having() and their and* and or* counterparts have been refactored to reduce code duplication.
  2. The QueryBuilder tests that call $qb->expr() but don't use the return value have been cleaned up.

$selects = is_array($select) ? $select : func_get_args();

return $this->add('select', $selects, true);
return $this->add('select', array_merge([$expression], $expressions), true);
Copy link
Member

Choose a reason for hiding this comment

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

This is changing the behaviour since the first argument could be an array already.

Copy link
Member Author

Choose a reason for hiding this comment

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

I should have probably changed the parameter type in the annotation from mixed to string. This is already reflected in the upgrade notes and there's another PR coming: morozov/dbal@issues/3825...morozov:issues/3825-NEXT.

Copy link
Member Author

@morozov morozov Jan 18, 2020

Choose a reason for hiding this comment

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

I enforced (actually, PHP_CodeSniffer forced me to) all expressions to be strings.

$groupBy = is_array($groupBy) ? $groupBy : func_get_args();

return $this->add('groupBy', $groupBy, false);
return $this->add('groupBy', array_merge([$expression], $expressions), false);
Copy link
Member

Choose a reason for hiding this comment

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

$groupBy = is_array($groupBy) ? $groupBy : func_get_args();

return $this->add('groupBy', $groupBy, true);
return $this->add('groupBy', array_merge([$expression], $expressions), true);
Copy link
Member

Choose a reason for hiding this comment

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

@morozov morozov force-pushed the issues/3825 branch 2 times, most recently from 3f16961 to 8744c78 Compare January 18, 2020 20:24
@morozov morozov requested a review from lcobucci January 18, 2020 20:32
@@ -501,21 +499,16 @@ public function distinct() : self
* ->leftJoin('u', 'phonenumbers', 'u.id = p.user_id');
* </code>
*
* @param mixed $select The selection expression.
* @param string $expression The selection expressions.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @param string $expression The selection expressions.
* @param string $expression The selection expression.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, addressed.

Copy link
Member

@beberlei beberlei left a comment

Choose a reason for hiding this comment

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

I think this makes sense, because the array support really only exists because at the time we added this feature the ... syntax didn't exist yet.

But it will be essential that we trigger_error(E_USER_DEPRECATED) here, because this only deprecates half the method, and its not easy to find these in your own code base given how this is probably spread in hundreds of places for a mid-sizied application that uses DBAL QueryBuilder.

@morozov
Copy link
Member Author

morozov commented Jan 21, 2020

[…] the array support really only exists because at the time we added this feature the ... syntax didn't exist yet.

This was my thought too. The current API allows mixing arrays and variadic arguments and will silently drop the latter in favor of the former.

@morozov morozov merged commit 9728d99 into doctrine:master Jan 21, 2020
@morozov morozov deleted the issues/3825 branch January 21, 2020 15:56
@morozov
Copy link
Member Author

morozov commented Jan 21, 2020

But it will be essential that we trigger_error(E_USER_DEPRECATED) here

What I'm not really sure is how seeing a deprecation error while upgrading to a minor version is better from the developer experience standpoint than seeing failure after an upgrade to the next major. In both cases, the code in question will need to be triggered either by a test or manually.

Upgrading to a new major w/o testing the code is irresponsible, and runtime errors won't save you from that.

Besides that, in order to see an error suppressed with @, you'll also need a special error handler which not every application has.

@morozov morozov self-assigned this Jan 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace func_get_args with variadic arguments where possible in the API
4 participants