Answer the question
In order to leave comments, you need to log in
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();
Answer the question
In order to leave comments, you need to log in
the getSingleton() method needs a comment /** return singleton */
/**
* @return singleton
*/
public function getSingleton(){
// и даже по цепочке должно работать
/**
* @return singleton
*/
public static function getInstance() {
Easy way: use /** var */ as far as I understand.
Those. something like
/** @var $system singleton */
the getSingleton() method needs a comment /** return singleton */
/**
* @return singleton
*/
public function getSingleton(){
// и даже по цепочке должно работать
/**
* @return singleton
*/
public static function getInstance() {
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 questionAsk a Question
731 491 924 answers to any question