Skip to content

[Serializer] Extract types of constructor parameters from docblock comment #25524

@sergeyfedotov

Description

@sergeyfedotov
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version ?

Currenly PhpDocExtractor works only with class properties. It's not possible to clarify the type of the constructor parameter through docblock comment.

class A
{
    private $b;

    /**
     * @param B[] $b
     */
    public function __construct(array $b)
    {
        $this->b = $b;
    }

    public function getB()
    {
        return $this->b;
    }
}

class B
{
    private $c;

    public function __construct($c)
    {
        $this->c = $c;
    }

    public function getC()
    {
        return $this->c;
    }
}

$a = $serializer->denormalize(['b' => [['c' => 1], ['c' => 2], ['c' => 3]]], A::class);
print_r($a);

Expected result:

App\A Object
(
    [b:App\A:private] => Array
        (
            [0] => App\B Object
                (
                    [c:App\B:private] => 1
                )
            [1] => App\B Object
                (
                    [c:App\B:private] => 2
                )
            [2] => App\B Object
                (
                    [c:App\B:private] => 3
                )
        )
)

Actual result:

App\A Object
(
    [b:App\A:private] => Array
        (
            [0] => Array
                (
                    [c] => 1
                )
            [1] => Array
                (
                    [c] => 2
                )
            [2] => Array
                (
                    [c] => 3
                )
        )
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy