Proxy generator does not respect optional parameter type hint #5369

Closed
opened 2026-01-22 15:05:37 +01:00 by admin · 4 comments
Owner

Originally created by @iluuu1994 on GitHub (Dec 29, 2016).

Originally assigned to: @Ocramius on GitHub.

If a setter method has an optional parameter Doctrine will simply ignore it in the generated classes thus generating a warning:

Declaration of A::setId(int $id) should be compatible with B::setId(?int $id)`

The setter looks like this:

public function setId(?int $id)
{
    $this->id = $id;
}

And here is the proxy:

public function setId(int $id)
{
    $this->__initializer__ && $this->__initializer__->__invoke($this, 'setId', [$id]);
    return parent::setId($id);
}

This should either throw an error or properly copy the optional parameter to the proxy method definition.

Originally created by @iluuu1994 on GitHub (Dec 29, 2016). Originally assigned to: @Ocramius on GitHub. If a setter method has an optional parameter Doctrine will simply ignore it in the generated classes thus generating a warning: > Declaration of A::setId(int $id) should be compatible with B::setId(?int $id)` The setter looks like this: ```php public function setId(?int $id) { $this->id = $id; } ``` And here is the proxy: ```php public function setId(int $id) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setId', [$id]); return parent::setId($id); } ``` This should either throw an error or properly copy the optional parameter to the proxy method definition.
admin added the Duplicate label 2026-01-22 15:05:37 +01:00
admin closed this issue 2026-01-22 15:05:39 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 29, 2016):

Please verify that you are running against doctrine/common 2.7.1

@Ocramius commented on GitHub (Dec 29, 2016): Please verify that you are running against [doctrine/common 2.7.1](https://github.com/doctrine/common/releases/tag/v2.7.1)
Author
Owner

@iluuu1994 commented on GitHub (Dec 29, 2016):

Ok, I'm indeed not running doctrine/common 2.7.1:

doctrine/annotations                 v1.3.0             Docblock Annotations Parser
doctrine/cache                       v1.6.1             Caching library offering an object-oriented API for many cache backends
doctrine/collections                 v1.3.0             Collections Abstraction library
doctrine/common                      v2.6.2             Common Library for Doctrine projects
doctrine/dbal                        v2.5.5             Database Abstraction Layer
doctrine/doctrine-bundle             1.6.4              Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.3.0              Symfony Bundle for Doctrine Cache
doctrine/inflector                   v1.1.0             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                1.0.5              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                       v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm                         v2.5.6             Object-Relational-Mapper for PHP

This is what my composer.json looks like:

"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.3",

It looks like I'm running the latest versions of those though. Should doctrine/common 2.7.1 be fetched by any of those yet?

@iluuu1994 commented on GitHub (Dec 29, 2016): Ok, I'm indeed not running `doctrine/common 2.7.1`: ``` doctrine/annotations v1.3.0 Docblock Annotations Parser doctrine/cache v1.6.1 Caching library offering an object-oriented API for many cache backends doctrine/collections v1.3.0 Collections Abstraction library doctrine/common v2.6.2 Common Library for Doctrine projects doctrine/dbal v2.5.5 Database Abstraction Layer doctrine/doctrine-bundle 1.6.4 Symfony DoctrineBundle doctrine/doctrine-cache-bundle 1.3.0 Symfony Bundle for Doctrine Cache doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plural rules. doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers. doctrine/orm v2.5.6 Object-Relational-Mapper for PHP ``` This is what my `composer.json` looks like: ``` "doctrine/orm": "^2.5", "doctrine/doctrine-bundle": "^1.6", "doctrine/doctrine-cache-bundle": "^1.3", ``` It looks like I'm running the latest versions of those though. Should `doctrine/common 2.7.1` be fetched by any of those yet?
Author
Owner
@Ocramius commented on GitHub (Dec 29, 2016): Closing as duplicate of https://github.com/doctrine/doctrine2/issues/6176, https://github.com/doctrine/doctrine2/issues/6157, https://github.com/doctrine/doctrine2/pull/6156
Author
Owner

@iluuu1994 commented on GitHub (Dec 29, 2016):

Cool, thank you @Ocramius for your very fast reply!

@iluuu1994 commented on GitHub (Dec 29, 2016): Cool, thank you @Ocramius for your very fast reply!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5369