is there a way to use any class as property type in @property ?

Is there a way to 'cheat' in phpstorms autocomplete to force it to see non-standard PHP types as magic properties?

for example:

/**
* @property $title string
* @property $content string
* @property $postdate DateTime
**/

    class Article {

...
...

     }


somewhere outside the class I want to do the following and get PHPStorm to recognise postdate as a DateTime object for auto-complete:

$a = new Article();
$a->postdate->

is this possible somehow? It is important that the property must remain magic and not public (since I can't intercept setting a public property for validation).

2 comments
Comment actions Permalink

Hi there,

Is there a way to 'cheat' in phpstorms autocomplete to force it to see non-standard PHP types as magic properties?

Yes.

is this possible somehow?

Yes.

Start with reading documentation about *correct syntax*.

/**
* @property string $title
* @property string $content
* @property \DateTime $postdate Optional description here
*/
class Article
{
}

$a = new Article();
$a->postdate->

0
Comment actions Permalink

Thanks! Can't believe I didn't notice I had them in the wrong order :)

0

Please sign in to leave a comment.