0

Is there a way to make Eclipse give code hints to variables created from objects? For example if I create a new variable:

$db = new mysqli('server', 'user', 'pwd', 'database');

then $db-> brings up code hints, but if I do:

$query = 'Select * From thisTable';
$result = $db->query($query);

but then if I use:

$result->

I do not get any code hints.. I'm pretty new to Eclipse and PHP. I have searched around but could not find anything related to this. I did notice while trying out the new version of Dreamweaver CS5.5 it does do code hinting for the above scenario.

1 Answer 1

2

Most PHP IDEs rely (mainly) on the PHPDoc when computing the code assist suggestions. This is quite a must for dynamic languages such as PHP, since the type-binding is very 'flexible'.

You may hit some limitations in the IDE capability to assist you in some cases (such as the case you defined). In these cases, some IDE's provide mechanisms to specifically the variable type. In your case, the returned type is 'mixed' (see php.net), so you have to define what it is.

It might be hard to find out in this specific case, but in general, this is how you hint the IDE with a variable type.

In PDT:

$a = callSomeFunction();
/* @var $a PDO */
$a -> // will give you the PDO code assist for $a

Other IDEs also have similar capabilities.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, I was able to add in the /* @var $result mysqli_result */ to get the code hinting I wanted. Now I should be able to do that with any other variable I want code hinting on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.