Search code examples
phpstormlaravel-5.3

Laravel and @property-write errors in PhpStorm


I'm not sure why I'm seeing this error. I'm a newbie to the PhpStorm IDE and didn't see these kinds of errors when I was developing in SublimeText2/3.

enter image description here The error when I hover over the red text just says @property-write

In my Users Model class it looks like this:

enter image description here

What am I doing wrong? What are the best practices to fix errors like these?


Solution

  • Property declared using PHPDoc's @property-write tag represents a property that can have write-only access outside of the class (i.e. you can write to it/assign new value but cannot read from it).

    In your example you are trying to read from that property.

    https://phpdoc.org/docs/latest/references/phpdoc/tags/property-write.html


    What am I doing wrong?

    First of all -- who did generate that @propert-write mixed $timezone line in first place?

    (without knowing your project details)

    • Maybe you are using wrong tag (maybe it meant to be just @property)?
    • If that tag is correct one then you should not be using this field this way

    What are the best practices to fix errors like these?

    The most common fix would be just changing the tag to be @property -- it will allow both write and read access.


    I'm a newbie to the PhpStorm IDE and didn't see these kinds of errors when I was developing in SublimeText2/3.

    PhpStorm knows more about your code (PHP in this particular case) because of its Inspections. You may also install 3rd party "Php Inspections (EA Extended)" plugin to add even more inspections.