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

Void methods in collections causing fatal error #2256

Closed
Lewiatan opened this issue Dec 2, 2020 · 2 comments · Fixed by #2261
Closed

Void methods in collections causing fatal error #2256

Lewiatan opened this issue Dec 2, 2020 · 2 comments · Fixed by #2261
Milestone

Comments

@Lewiatan
Copy link

Lewiatan commented Dec 2, 2020

Bug Report

I have a collection that extends Doctrine\Common\Collections\ArrayCollection which is persisted to database. This collection has methods that returns void, for example:

public function removeProduct(ProductId $productId): void
    {
        $index = $this->indexOf($productId);

        if ($index !== false) {
            $this->remove($index);
        }
    }

The generated persistent collection is trying to return value from void method:

/**
     * {@inheritDoc}
     */
    public function removeProduct(ProductId $productId): void
    {
        $this->initialize();
        if ($this->needsSchedulingForSynchronization()) {
            $this->changed();
        }
        return $this->coll->removeProduct($productId);
    }

I updated symfony recently, and during that process doctrine/common was also updated. I think that with doctrine/common in version 2.12 it was working, but I'm not 100% sure if I had outdated cache. I can verify that if needed.

Package Version
doctrine/mongodb-odm-bundle 4.2.2
doctrine/common 3.0.2

How to reproduce

  1. Create collection that is persisted to database
  2. Add void method
  3. Try to store collection

Expected behavior

Void methods are supported by proxy classes

@malarzm malarzm added the Bug label Dec 2, 2020
@malarzm malarzm added this to the 2.1.3 milestone Dec 2, 2020
@malarzm
Copy link
Member

malarzm commented Dec 2, 2020

@Lewiatan thank you for the bug report! The collection code is generated in ODM itself, if you'd want to take a stab at fixing the bug it's here:

return \$this->coll->{$method->name}($callParamsString);
. The generated code template needs to have the return part removed if void is declared as a return type. You'd also need to add a test case, here's a good candidate to add it to: https://github.com/doctrine/mongodb-odm/blob/3bdfe97be472160ebbc924d5882ce61bd640a515/tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php.

@Lewiatan
Copy link
Author

Lewiatan commented Dec 3, 2020

Sure, I'll give it a try ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants