-1

Here is my sample code which is what I want to get, but in User class I get no codecompletion (for $this->app) in PHPSotrm. How to change that code to enable code completion? I want to avoid global.

namespace myApp

class app
{
    public $pdo = "my PDO";

    public function __construct() {
        $this->user=new User($this);
        $this->test=new Test($this);
        echo $this->user->getPDO(); 
        //"my PDO"
        echo $this->test->getUserPDO(); 
        //"my PDO"
    }
}

class User
{
    private $app=null;

    public function __construct($app) {
        $this->app=$app;
    }
    public function getPDO() {
        return $this->app->pdo;
        //no code completion
    }
}

class Test
{
    private $app=null;

    public function __construct($app) {
        $this->app=$app;
    }
    public function getUserPDO() {
        return $this->app->user->getPDO;
        //no code completion
    }
}
piernik
  • 3,507
  • 3
  • 42
  • 84
  • 1
    possible duplicate of [JetBrains WebIDE: PHP variable type hinting?](http://stackoverflow.com/questions/1816641/jetbrains-webide-php-variable-type-hinting) – Sergiu Paraschiv Oct 24 '14 at 12:24

1 Answers1

1

There's plenty of information on how to achieve this. All you need to do is to add the PHPDoc describing the property type.

class User
{
    /**
     * @var App
     */   
    private $app=null;

    /**
     * @param App $app
     */
    public function __construct($app) {
        $this->app = $app;
    }

    /**
     * @return PDO
     */
    public function getPDO() {
        return $this->app->pdo;
    }
}

If properties are implemented via magic getters / setters, you can use the same principles on the class itself.

/**
 * @property App $app
 * @method Pdo getPdo()
 */
class User
{
    // …
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72