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 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘