问题描述
我在Zend Framework项目中获得了以下类:
I've got the following class in a Zend Framework project:
<?php
/**
* User's class
*
* This class should be responsible for all
*
* @author Steve Davies
* @copyright 2012
* @version SVN: $Id$
*/
class Api_Admin_Users extends Api_Core
{
/**
* Class Constructor
*
* @return void
*/
public function __construct() {
parent::__construct();
}
/**
* Get User's name
*
* This returns the user's name
*
* @return void
*/
public function new() {
$user = self::_instance()->_em->getRepository('UserManagement\Users')->find('1');
echo $user->getFullName();
}
}
然而,当我尝试使用代码暗示 $ user-> getFullName();
,它不起作用。
However when I try and use code hinting on $user->getFullName();
, it doesn't work.
使用以下技巧从,它的作品:
Using the following trick from here, it works:
/**
* Get User's name
*
* This returns the user's name
*
* @return void
*/
public function new() {
/* @var $user \UserManagement\Users */
$user = self::_instance()->_em->getRepository('UserManagement\Users')->find('1');
echo $user->getFullName();
}
但是,我不想包括每次我实例化对象的注释行。当我尝试将其移动到类定义 - 甚至方法定义,它无法工作。
But, I don't want to have to include that comment line everytime I instantiate the object. When I try to move this to the Class definition - or even the method definition, it fails to work.
任何人都可以为此提供答案?
Can anyone provide an answer for this?
推荐答案
PHP是一种动态语言,因此从静态代码分析中推断出变量类型(例如Java中)并不是简单的方法。
PHP is a dynamic language and as such it is not trivial to infer variable types from static code analysis (like it is in Java for example).
使用工厂方法,例如您的 getRepository('UserManagement\Users')
特别困难。
It's especially difficult with factory methods like yours getRepository('UserManagement\Users')
.
NetBeans目前无法知道如何将函数参数转换为返回变量的类型(除非您对某些父类感到满意,所有父类从其返回的所有子类该工厂派生)。不幸的vdoc是处理这种情况的唯一方法。
NetBeans currently has no way of knowing how to translate the function argument to the type of returned variable (unless you're satisfied with some parent class from which all subclasses returned by that factory derive). Unfortunatelly vdoc's are the only way to deal with such cases.
这篇关于Netbeans自动完成不适用于自定义PHP类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!