Thanks to visit codestin.com
Credit goes to github.com

Skip to content

func_get_args() call order fix for HHVM bug#1142

Merged
Ocramius merged 1 commit into
doctrine:2.4from
BenjaminNolan:2.4
Sep 22, 2014
Merged

func_get_args() call order fix for HHVM bug#1142
Ocramius merged 1 commit into
doctrine:2.4from
BenjaminNolan:2.4

Conversation

@BenjaminNolan
Copy link
Copy Markdown

Firstly, so no-one closes this as ENOTONMASTER, @Ocramius told me to open it directly against 2.4. :)

This PR fixes bugs in Doctrine\ORM\QueryBuilder where the values provided to method arguments to ::andWhere(), ::orWhere(), ::andHaving(), and ::orHaving() are overwritten by code within the methods in HHVM and PHP7.

After much fun and headscratching in both #doctrine and #hhvm on Freenode, we discovered that in the following code, $where = $this->getDqlPart('where'); overwrites the values stored internally for the $where parameter of the function which is returned by func_get_args():

public function orWhere($where)
{
    $where = $this->getDqlPart('where');
    $args  = func_get_args();
}

This means that instead of $args being set as expected to an array containing the string or object provided to the function, it actually contains the object returned by QueryBuilder::getDqlPart(), which causes all the problems you'd expect it to.

This PR simply swaps the order of the calls so that the function arguments are retrieved via func_get_args() before the $where variable is modified, fixing the problem.

@doctrinebot
Copy link
Copy Markdown

Hello,

thank you for creating this pull request. However did not open it on the "master"
branch. Our Git workflow requires all pull requests to go through "master" branch
and the release masters then merge them back into stable branches, if they are
bug fixes.

Please open the pull request again for the "master" branch and close
this one.

Nevertheless I have opened a Jira ticket for this Pull Request to track this
issue:

http://www.doctrine-project.org/jira/browse/DDC-3317

We use Jira to track the state of pull requests and the versions they got
included in.

@Ocramius
Copy link
Copy Markdown
Member

Related: facebook/hhvm#3816

@Ocramius Ocramius self-assigned this Sep 22, 2014
@Ocramius
Copy link
Copy Markdown
Member

@TwoWholeWorms can you also check if this affects master in any way?

@BenjaminNolan
Copy link
Copy Markdown
Author

By the looks of it, it's already been fixed in all these functions in master (which I'd guess is the 2.5.*-dev tree), so I think the 2.4-only fix should suffice. I could back-port it further, but I highly doubt anyone is using anything earlier than 2.4 on HHVM. Actually, TBH, I highly doubt anyone is using 2.4 on HHVM at all, since it's, y'know… b0rked.

@Ocramius
Copy link
Copy Markdown
Member

Ok, fine with merging then. I'll also tag.

Ocramius added a commit that referenced this pull request Sep 22, 2014
func_get_args() call order fix for HHVM bug
@Ocramius Ocramius merged commit a50ae2c into doctrine:2.4 Sep 22, 2014
@till
Copy link
Copy Markdown

till commented Nov 3, 2014

@Ocramius @TwoWholeWorms — Doesn't look like this fixes much? A test case would have been nice.

greg0ire pushed a commit to sonata-project/SonataDoctrineORMAdminBundle that referenced this pull request Oct 1, 2017
core23 pushed a commit to sonata-project/SonataDoctrineORMAdminBundle that referenced this pull request Oct 2, 2017
TomiBelan added a commit to fmfi-svt/anketa that referenced this pull request May 8, 2025
needed for compatibility with PHP >= 7.0 to fix a bug in andWhere(). it built a
query that contains itself, which crashed from infinite recursion when executed.
fixed in 2.5: doctrine/orm#1164
different fix in 2.4: doctrine/orm#1142

updating directly to doctrine 2.5 might also work, but it is not 100% backwards
compatible. for now i only did the minimum necessary update. maybe later.
https://web.archive.org/web/20170521161209/http://docs.doctrine-project.org/en/latest/changelog/migration_2_5.html
https://www.doctrine-project.org/2015/04/02/orm-2-5-0.html
TomiBelan added a commit to fmfi-svt/anketa that referenced this pull request Jul 15, 2025
needed for compatibility with PHP >= 7.0 to fix a bug in andWhere(). it built a
query that contains itself, which crashed from infinite recursion when executed.
fixed in 2.5: doctrine/orm#1164
different fix in 2.4: doctrine/orm#1142

updating directly to doctrine 2.5 might also work, but it is not 100% backwards
compatible. for now i only did the minimum necessary update. maybe later.
https://web.archive.org/web/20170521161209/http://docs.doctrine-project.org/en/latest/changelog/migration_2_5.html
https://www.doctrine-project.org/2015/04/02/orm-2-5-0.html
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