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 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等