Reputation: 8800
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?
Upvotes: 0
Views: 529
Reputation: 3838
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!
Upvotes: 2