Code Monkey home page Code Monkey logo

Comments (2)

romm avatar romm commented on September 28, 2024 1

Thanks for the report. @wengooooo this should be fixed with #497.

What is "weird" is needing to use the @param tag on the function phpDoc, else the mapper will recognize the array definition as array and fail. Using @var above the parameter will not work. A working example would have SomeClass defined like this.

@hollow3464 this behavior is intended, using @var works on properties, or when a constructor's parameter is also a promoted property:

// NOT OK:
final class Foo
{
    public array $values;

    public function __construct(
        /** @var array<string> */
        array $values
    ) {
        $this->values = $values;
    }
}

// OK:
final class Foo
{
    public array $values;

    /**
     * @param array<string> $values
     */
    public function __construct(
        array $values
    ) {
        $this->values = $values;
    }
}

// OK:
final class Foo
{
    public function __construct(
        /** @var array<string> */
        public array $values
    ) {}
}

from valinor.

hollow3464 avatar hollow3464 commented on September 28, 2024

You can only create readonly properties through a constructor.

If you remove the readonly statement it will work. It will also work if you write a constructor that does the property assignments properly.

When using a constructor, every property must me initialized or will remain uninitialized as the mapper will only use the constructor for variable assigment. Please refer to the language docs for usage on readonly props usage.

What is "weird" is needing to use the @param tag on the function phpDoc, else the mapper will recognize the array definition as array<mixed> and fail. Using @var above the parameter will not work. A working example would have SomeClass defined like this.

final class SomeClass
{
    public readonly string $description;

    /** @var array<Identifier> */
    public array $identifier;

    /**
     * @param array<Identifier> $identifier
     */
    public function __construct(
        string $description,
        array $identifier,
    ) {
        $this->description = $description;
        $this->identifier = $identifier;
    }
}

from valinor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.