Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Autocomplete type hinting
Autocomplete type hinting [message #14112] Mon, 16 April 2007 21:08 Go to next message
Emil Ivanov is currently offline Emil IvanovFriend
Messages: 12
Registered: July 2009
Junior Member
Hi,

I've been using PDT/Xdebug for a while and I find it really good.

One thing I'm not geting, though - I have some method returning an object -
on the new var I don't get autocomplete, because it doesn't know its type. I
tried hinting it using phpdoc, but it doesn't seem to work.

Any help would be appreciated.

Regards,
Emil Ivanov
Re: Autocomplete type hinting [message #14131 is a reply to message #14112] Mon, 16 April 2007 21:12 Go to previous messageGo to next message
Emil Ivanov is currently offline Emil IvanovFriend
Messages: 12
Registered: July 2009
Junior Member
Many appologies - I just managed to figure it out myself.

The sollution is to add the pphpdoc AFTER the variable. I was used to
PHPed's convention, which requires me to add it before the var.
I'm sorry, again, for the flood.

Take care and keep up the good work!

"Emil Ivanov" <emil.vladev@gmail.com> wrote in message
news:f00ojf$efv$1@build.eclipse.org...
> Hi,
>
> I've been using PDT/Xdebug for a while and I find it really good.
>
> One thing I'm not geting, though - I have some method returning an
> object - on the new var I don't get autocomplete, because it doesn't know
> its type. I tried hinting it using phpdoc, but it doesn't seem to work.
>
> Any help would be appreciated.
>
> Regards,
> Emil Ivanov
>
Re: Autocomplete type hinting [message #14148 is a reply to message #14131] Tue, 17 April 2007 00:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: apaz.yahoo.com

I wouldn't think that's a user error. documentation typically goes
before the variable declaration. I would log it at least as an
enhancement (if not a bug).

-a.

Emil Ivanov wrote:
> Many appologies - I just managed to figure it out myself.
>
> The sollution is to add the pphpdoc AFTER the variable. I was used to
> PHPed's convention, which requires me to add it before the var.
> I'm sorry, again, for the flood.
>
> Take care and keep up the good work!
>
> "Emil Ivanov" <emil.vladev@gmail.com> wrote in message
> news:f00ojf$efv$1@build.eclipse.org...
>> Hi,
>>
>> I've been using PDT/Xdebug for a while and I find it really good.
>>
>> One thing I'm not geting, though - I have some method returning an
>> object - on the new var I don't get autocomplete, because it doesn't know
>> its type. I tried hinting it using phpdoc, but it doesn't seem to work.
>>
>> Any help would be appreciated.
>>
>> Regards,
>> Emil Ivanov
>>
>
>
Re: Autocomplete type hinting [message #14200 is a reply to message #14148] Tue, 17 April 2007 09:55 Go to previous messageGo to next message
Emil Ivanov is currently offline Emil IvanovFriend
Messages: 12
Registered: July 2009
Junior Member
Logged as an echantment request:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=182693

"Andres Paz" <apaz@yahoo.com> wrote in message
news:4624105F.6050008@yahoo.com...
>I wouldn't think that's a user error. documentation typically goes before
>the variable declaration. I would log it at least as an enhancement (if not
>a bug).
>
> -a.
>
> Emil Ivanov wrote:
>> Many appologies - I just managed to figure it out myself.
>>
>> The sollution is to add the pphpdoc AFTER the variable. I was used to
>> PHPed's convention, which requires me to add it before the var.
>> I'm sorry, again, for the flood.
>>
>> Take care and keep up the good work!
>>
>> "Emil Ivanov" <emil.vladev@gmail.com> wrote in message
>> news:f00ojf$efv$1@build.eclipse.org...
>>> Hi,
>>>
>>> I've been using PDT/Xdebug for a while and I find it really good.
>>>
>>> One thing I'm not geting, though - I have some method returning an
>>> object - on the new var I don't get autocomplete, because it doesn't
>>> know its type. I tried hinting it using phpdoc, but it doesn't seem to
>>> work.
>>>
>>> Any help would be appreciated.
>>>
>>> Regards,
>>> Emil Ivanov
>>>
>>
Re: Autocomplete type hinting [message #14234 is a reply to message #14200] Tue, 17 April 2007 14:37 Go to previous messageGo to next message
exceptione is currently offline exceptioneFriend
Messages: 96
Registered: July 2009
Member
I think this is a bug. You should therefore not list this as an enhancement
request. Once this bug is fixed, you need to change all your variable
documentation. In addition, php documentation tools won't process comments
below variables. This is critical, if not blocker!

"Emil Ivanov" <emil.vladev@gmail.com> schreef in bericht
news:f025ib$kdq$1@build.eclipse.org...
> Logged as an echantment request:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=182693
>
> "Andres Paz" <apaz@yahoo.com> wrote in message
> news:4624105F.6050008@yahoo.com...
>>I wouldn't think that's a user error. documentation typically goes before
>>the variable declaration. I would log it at least as an enhancement (if
>>not a bug).
>>
>> -a.
>>
>> Emil Ivanov wrote:
>>> Many appologies - I just managed to figure it out myself.
>>>
>>> The sollution is to add the pphpdoc AFTER the variable. I was used to
>>> PHPed's convention, which requires me to add it before the var.
>>> I'm sorry, again, for the flood.
>>>
>>> Take care and keep up the good work!
>>>
>>> "Emil Ivanov" <emil.vladev@gmail.com> wrote in message
>>> news:f00ojf$efv$1@build.eclipse.org...
>>>> Hi,
>>>>
>>>> I've been using PDT/Xdebug for a while and I find it really good.
>>>>
>>>> One thing I'm not geting, though - I have some method returning an
>>>> object - on the new var I don't get autocomplete, because it doesn't
>>>> know its type. I tried hinting it using phpdoc, but it doesn't seem to
>>>> work.
>>>>
>>>> Any help would be appreciated.
>>>>
>>>> Regards,
>>>> Emil Ivanov
>>>>
>>>
>
Re: Autocomplete type hinting [message #14249 is a reply to message #14234] Tue, 17 April 2007 16:01 Go to previous messageGo to next message
Christian Müller is currently offline Christian MüllerFriend
Messages: 9
Registered: July 2009
Junior Member
Exception e schrieb:
> I think this is a bug.

I dont't think of it as a Bug.

> In addition, php documentation tools won't process comments
> below variables.

It's not a bug, since these Code-Hints are not PHPDocs.
The correct syntax (as stated in PDT's help) is:
/* @var $Foo MyFoo */
This ist just a comment, not a PHPDoc.
You can use /**, but that's just optional and in respect to a
documentation tool plain wrong, IMHO.

I can't think of a documentation tool, that would make good use of such
a PHPDoc regardless of it's position compared to the hinted variable.
Since these variables are not in any structured position within the
code, but somewhere a documentation tool wouldn't expect a PHPDoc anyway.


>
> "Emil Ivanov" <emil.vladev@gmail.com> schreef in bericht
> news:f025ib$kdq$1@build.eclipse.org...
>> Logged as an echantment request:
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=182693
>>
>> "Andres Paz" <apaz@yahoo.com> wrote in message
>> news:4624105F.6050008@yahoo.com...
>>> I wouldn't think that's a user error. documentation typically goes before
>>> the variable declaration. I would log it at least as an enhancement (if
>>> not a bug).
>>>
>>> -a.
>>>
>>> Emil Ivanov wrote:
>>>> Many appologies - I just managed to figure it out myself.
>>>>
>>>> The sollution is to add the pphpdoc AFTER the variable. I was used to
>>>> PHPed's convention, which requires me to add it before the var.
>>>> I'm sorry, again, for the flood.
>>>>
>>>> Take care and keep up the good work!
>>>>
>>>> "Emil Ivanov" <emil.vladev@gmail.com> wrote in message
>>>> news:f00ojf$efv$1@build.eclipse.org...
>>>>> Hi,
>>>>>
>>>>> I've been using PDT/Xdebug for a while and I find it really good.
>>>>>
>>>>> One thing I'm not geting, though - I have some method returning an
>>>>> object - on the new var I don't get autocomplete, because it doesn't
>>>>> know its type. I tried hinting it using phpdoc, but it doesn't seem to
>>>>> work.
>>>>>
>>>>> Any help would be appreciated.
>>>>>
>>>>> Regards,
>>>>> Emil Ivanov
>>>>>
>
>
Re: Autocomplete type hinting [message #15101 is a reply to message #14131] Wed, 18 April 2007 07:24 Go to previous messageGo to next message
Piotr Szczepanik is currently offline Piotr SzczepanikFriend
Messages: 13
Registered: July 2009
Junior Member
Emil Ivanov wrote:
> The sollution is to add the pphpdoc AFTER the variable. I was used to
> PHPed's convention, which requires me to add it before the var.
> I'm sorry, again, for the flood.

Hello Emil,
As I understand you are trying to hint a variable's type.
Why not trying to hint the function's return type through PHPDoc? Like that:

/**
* Short description
*
* @return companyClass
*/
function createCompany() {
...
return new companyClass();
}

Using this:
$company = createCompany();

I get a perfectly working code completion for companyClass' methods.
Of course companyClass' definition must be within the same project or
within the project or folder in "PHP Include Path" defined in Eclipse PDT.

Best regards,
Piotr Szczepanik
Re: Autocomplete type hinting [message #15125 is a reply to message #15101] Wed, 18 April 2007 09:39 Go to previous messageGo to next message
Christian Müller is currently offline Christian MüllerFriend
Messages: 9
Registered: July 2009
Junior Member
Piotr Szczepanik schrieb:
> Emil Ivanov wrote:
>> The sollution is to add the pphpdoc AFTER the variable. I was used to
>> PHPed's convention, which requires me to add it before the var.
>> I'm sorry, again, for the flood.
>
> Hello Emil,
> As I understand you are trying to hint a variable's type.
> Why not trying to hint the function's return type through PHPDoc? Like
> that:
>
> /**
> * Short description
> *
> * @return companyClass
> */
> function createCompany() {
> ...
> return new companyClass();
> }
>
> Using this:
> $company = createCompany();
>
> I get a perfectly working code completion for companyClass' methods.
> Of course companyClass' definition must be within the same project or
> within the project or folder in "PHP Include Path" defined in Eclipse PDT.

Hi Piotr,
you are perfectly correct. This is a) working for TypeHinting and b)
correctly parsable PHPDoc

But look at this construct (derived from yours):

/**
* Short description
*
* @return companyClass
*/
function createCompany() {
...
return array(new companyClass(), new companyClass(), ...);
}

Using this:
$companies = createCompany();

foreach ($companies as $company)
{
/* @var $company companyClass */
$company->
}

Here you would have no TypeHinting, if you leave out the /* @var.
You need to add this Comment after the definition of $company.
If you would add it before the definition, PDT would use some logic to
determine the Type of the variable and override your comment.



> Best regards,
> Piotr Szczepanik
Re: Autocomplete type hinting [message #15134 is a reply to message #15125] Wed, 18 April 2007 12:12 Go to previous messageGo to next message
Piotr Szczepanik is currently offline Piotr SzczepanikFriend
Messages: 13
Registered: July 2009
Junior Member
Christian Müller wrote:
> you are perfectly correct. This is a) working for TypeHinting and b)
> correctly parsable PHPDoc
>
> But look at this construct (derived from yours):
>
> /**
> * Short description
> *
> * @return companyClass
> */
> function createCompany() {
> ...
> return array(new companyClass(), new companyClass(), ...);
> }
Hi Christian,
writing my message I was assuming (as implied by Emil's first post) that
the function is returning an object. That's why I suggested documenting
the function itself.

> Using this:
> $companies = createCompany();
>
> foreach ($companies as $company)
> {
> /* @var $company companyClass */
> $company->
> }
> Here you would have no TypeHinting, if you leave out the /* @var.
That is also perfectly correct ;)

> You need to add this Comment after the definition of $company.
> If you would add it before the definition, PDT would use some logic to
> determine the Type of the variable and override your comment.
Strange. In my test case autocomplete is working perfectly even if I put
the type hinting above the variable's first use.

foreach ($companies as $companyXXX) {
/* @var $companyXXX companyClass */
$companyXXX->
}

Eclipse 3.2.2, PDT 0.7RC3, Java 1.5 (Linux and Windows).

Maybe it's caused by variable's name reuse for different purposes?
I don't know.

Best regards,
Piotr Szczepanik
Re: Autocomplete type hinting [message #15191 is a reply to message #15134] Wed, 18 April 2007 13:27 Go to previous messageGo to next message
Christian Müller is currently offline Christian MüllerFriend
Messages: 9
Registered: July 2009
Junior Member
Piotr Szczepanik schrieb:

>> You need to add this Comment after the definition of $company.
>> If you would add it before the definition, PDT would use some logic to
>> determine the Type of the variable and override your comment.
> Strange. In my test case autocomplete is working perfectly even if I put
> the type hinting above the variable's first use.
>

Nono, everything's fine.
You just mixed 'first use' with 'definition'
In our example the Definition is
$companies as $companyXXX
and the comment follows ^^


> foreach ($companies as $companyXXX) {
> /* @var $companyXXX companyClass */
> $companyXXX->
> }
>
> Eclipse 3.2.2, PDT 0.7RC3, Java 1.5 (Linux and Windows).
>
> Maybe it's caused by variable's name reuse for different purposes?
> I don't know.
>
> Best regards,
> Piotr Szczepanik
Re: Autocomplete type hinting [message #15255 is a reply to message #14249] Wed, 18 April 2007 13:34 Go to previous messageGo to next message
Emil Ivanov is currently offline Emil IvanovFriend
Messages: 12
Registered: July 2009
Junior Member
Yes,

I got your point.

Now I left this as an enchantment to colorize the comment
/* @var $db PDO */
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=182693)
Thank you all for the replies.

Take care,
Emil Ivanov
Re: Autocomplete type hinting [message #15448 is a reply to message #15191] Wed, 18 April 2007 18:22 Go to previous message
Piotr Szczepanik is currently offline Piotr SzczepanikFriend
Messages: 13
Registered: July 2009
Junior Member
Christian Müller wrote:
> Nono, everything's fine.
> You just mixed 'first use' with 'definition'
No. I was meaning the 'first use' in that sentence. Above the
$companyXXX->....

> In our example the Definition is
> $companies as $companyXXX
> and the comment follows ^^
That's right ;)

But in my opinion it actually does not matter where you put it.
I use some templates in my application and (for convenience) put the
typehinting for variables which results from foreach loops at the top of
my template file and it also works perfectly well.

Like that:
<?php
/* @var $company companyClass */
/* @var $project projectClass */
?>
<div>
<?php foreach ($companies as $company): ?>
<div><?php echo $company->| Here I have autocomplete for
companyClass instance ?></div>
<?php endforeach; ?>
</div>

The markup is just example.

I've just checked that and it works.

Best regards,
Piotr
Previous Topic:Help - Project Navigator
Next Topic:debuging from mozilla with zend eclipse plugin
Goto Forum:
  


Current Time: Fri Jan 24 15:28:06 GMT 2025

Powered by FUDForum. Page generated in 0.03326 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top