donglie1994 2012-01-18 13:38
浏览 45
已采纳

Aptana Studio 3混合类型的PHP代码完成?

I am currently working in Aptana Studio 3 (which appears to be 3.0.7 at this time) using PHP. I have a function that will return an instance of another object, but that object is determined at run-time. Therefore, it is not possible to decorate the function with relevant comments. Instead, I am looking for a clean solution to decorare the caller with tags for code complete. How can I do this?

/**
 * Represents a person.
 */
class Person
{
    /**
     * Contains the identifier.
     *
     * @var int
     */
    public $PersonId;

    /**
     * Contains the string.
     *
     * @var string
     */
    public $Name;
}

/**
 * A simple factor example.
 * 
 * @return mixed
 */
function CreateExample( $zClass )
{
    return new $zClass();
}

/* @var $x Person */
$x = CreateExample( 'Person' ) instanceof Person;

After decoration with both a comment and instanceof, it finally worked, but this looks horrible! Is there no better way to use one solution and make it work as intended?

  • 写回答

1条回答 默认 最新

  • dongtu0363 2012-01-19 07:02
    关注

    Ok. First, I believe that CreateExample( 'Person' ) instanceof Person simply assign a primitive boolean into $x. That is also the reason you will not get code-assist on $x, even if you edit the return of CreateExample to @return Person.

    Setting $x = CreatePerson( 'Person' ); will get you the CA in case you have the CreateExample doc set-up correctly.

    Now, since you have a mixed returned type, one solution is to use the @var doc, as you did. However, there is another solution that you can use.

    I assume you know all the possible return types, so in that case you can pipe those types in the CreateExample @return:

    @return Person|OtherClass|ThirdClass

    Now, when you code-assist $x you will get an aggregation of all the available elements from all the classes you piped.

    Hope that helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀