P
P
Pavel Zaitsev2012-08-16 16:11:50
PHP
Pavel Zaitsev, 2012-08-16 16:11:50

Can PHPStorm recognize the returned object through a static method?

I recently installed this IDE for myself, so I'm trying to figure out what it can do. It will be faster to show. There is a code:

<?php

class system {

    public function getSingleton(){
        return singleton::getInstance();
    }

}

class singleton{

    public static $instance  = null; // Инстанс объекта данного класса

    private function __construct() {}
    private function __clone() {}

    /******************************/
    /* Возвращаем инстанс объекта */
    public static function getInstance() {
        if ( is_null( self::$instance ) ) {
            self::$instance = new singleton;
        }
        return self::$instance;
    }
    /* Возвращаем инстанс объекта */
    /******************************/

    public function test() {
        echo '1';
    }
}

$system = new system();

$object = $system->getSingleton();



When I type in the $object-> line, I expect to see a singleton class methods hint, but the IDE gives me a "No suggestion" message. Is it possible to teach the IDE to recognize the returned object?

IDE version 4.0.3.

Thanks in advance for the replies.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
W
winbackgo, 2012-08-16
@winbackgo

the getSingleton() method needs a comment /** return singleton */

/**
 * @return singleton
 */
public function getSingleton(){

// и даже по цепочке должно работать
/**
 * @return singleton
 */
public static function getInstance() {

F
Fr3nzy, 2012-08-16
@Fr3nzy

Easy way: use /** var */ as far as I understand.
Those. something like

/** @var $system singleton */

W
winbackgo, 2012-08-16
@winbackgo

the getSingleton() method needs a comment /** return singleton */

/**
 * @return singleton
 */
public function getSingleton(){

// и даже по цепочке должно работать
/**
 * @return singleton
 */
public static function getInstance() {

A
Anatoly, 2012-08-16
@taliban

Specify what type of variable your method returns, in the end, even in the factory there will be an addition, provided that each returned variable / property will have an explicitly specified type

/**
 * @var singleton
 */
public static $instance  = null; // Инстанс объекта данного класса

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question