Question

Given a php class like:

<?php

/**
 * A class description.
 *
 * @property int id
 * @property string name
 *
 */

class myClass {

  public function hasId() {
    if ($this->id) { 
      return true;
    } else {
      return false;
    }
  }

}
?>

I would like to have highlighting that $this->id is never declared. I know in PHP that isn't strictly required but our in house standards are asking for it. Is there a way to get this in Intellij/Idea?

Was it helpful?

Solution

If you remove your doc @property int id. You'll get the warning once you remove it. IntelliJ uses those docs as additional information about a class. You're basically telling IntellJ that the class does have those properties.

There is no way to tell IntelliJ to ignore those comments.

OTHER TIPS

//Main class 
class Main{

//Let main class has variable $id
public $id = '123';

}

class myClass extends Main{

  public function hasId() {
    //Check it!
    if (isset($this->id)) { 
      return true;
    } else {
      return false;
    }
  }

}

$newclass = new myClass;

var_dump($newclass->hasId());

Result:

bool(true)

If we comment line with variable declaration //public $id = '123';

Result:

bool(false)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top