This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 141652 - Offer CC for class members directly on functions returning object type
Summary: Offer CC for class members directly on functions returning object type
Status: VERIFIED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker with 1 vote (vote)
Assignee: Tomasz Slota
URL:
Keywords:
: 144161 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-07-25 08:51 UTC by Tomasz Slota
Modified: 2008-10-09 16:43 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Slota 2008-07-25 08:51:34 UTC
Currently CC for class members works only for variables of object type. It should also work for functions/methods returning object type, e.g.

<?php
class My {
    public function echoMy() {
        echo "echoMy\n";
    }        
}

/**
 * @return My
 */
function getMy() {
    return new my();
}
//doesn't work
getMy()->|
?>


This may be challenging to implement using the current infrastructure as I would need to operate on AST level (currently cc for class members operates on 
token level). Probably enhancements in 'code sanitation' would be required too. It is also possible to stick to the token level but then again it may get quite 
tricky...
Comment 1 Tomasz Slota 2008-08-18 12:23:59 UTC
*** Issue 144161 has been marked as a duplicate of this issue. ***
Comment 2 Tomasz Slota 2008-08-18 12:25:17 UTC
Changing issue type to P2 DEFECT
Comment 3 Tomasz Slota 2008-08-21 20:46:07 UTC
Fixed in 80%, 

http://hg.netbeans.org/main/rev/c6013dfee497
Comment 4 Quality Engineering 2008-08-22 06:10:39 UTC
Integrated into 'main-golden', available in build *200808220201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/c6013dfee497
User: Tomasz Slota <tslota@netbeans.org>
Log: #141652: Offer CC for class members directly on functions returning object type (part 1)
Comment 5 rmatous 2008-08-22 18:05:54 UTC
I have noticed that code:
$var = factory();//my comment
$var->| //echome()->echome()->echome();

works if you omit the comment "//my comment" 

Also this version doesn't work
$var = factory();
//my comment
$var->| //echome()->echome()->echome();

Comment 6 rmatous 2008-08-22 18:10:15 UTC
It would be great if also these pieces of code worked ($var2->|, $var3->|):
/**
 * @return ClsFromFactory
 */
function factory() {
    global $factoryVar;
    return $factoryVar;
}
$var = factory();
$var2 = $var;
$var2->| //->echome();//not working

$var3 = $var->echome();
$var3->| //echome();
Comment 7 rmatous 2008-08-22 18:12:53 UTC
Sorry for just code snip., follow this link for better context:
http://www.netbeans.org/nonav/issues/showattachment.cgi/68096/I144809.php
Comment 8 Tomasz Slota 2008-08-22 19:23:18 UTC
With this commit the fix can be considered complete:

http://hg.netbeans.org/main/rev/aacf5fb678ec
Comment 9 Quality Engineering 2008-08-23 05:24:36 UTC
Integrated into 'main-golden', available in build *200808230201* on http://bits.netbeans.org/dev/nightly/
Changeset: http://hg.netbeans.org/main/rev/7892e0e584bb
User: Tomasz Slota <tslota@netbeans.org>
Log: #141652: Offer CC for class members directly on functions returning object type (part 2)
Comment 10 rmatous 2008-08-27 05:16:55 UTC
I tried to fix somehow usecases that I mentioned in my comment Fri Aug 22 17:05:54 +0000 2008. Meaning usecases like:
$var3 = $var->echome();
$var3->| //echome();

Fixes:
type resolution for var assignments 
http://hg.netbeans.org/main/rev/068c6e98001c

type resolution for var assignments, part II - takes function parameters into acount 
http://hg.netbeans.org/main/rev/5f31008d19e9

type resolution for var assignments, part III - takes into acount assignments inside class containing $this,self,parent 
http://hg.netbeans.org/main/rev/dda52792b157
Comment 11 roti 2008-09-15 19:44:23 UTC
Hi!

 I found that it is still not working with version NetBeans IDE Dev (Build 200809150201)

MyMain.php:
<?php
class MyMain {
	function MyMain(){
	}
	function getParam($param01 = "default") {
		echo $param01;
	}
}
?>

MyMain2.php:
<?php
include_once 'MyMain.php';
function GetMyMain() {
	return new MyMain();
}
?>

index.php:
<?php
include_once 'MyMain.php';
include_once 'MyMain2.php';
$instance1 = new MyMain();
// code completion works ok
$instance1->getParam("MyString<br />");

$instance2=GetMyMain();
// code completion does not work:
$instance2->getParam();
?>


Roti
Comment 12 rmatous 2008-09-16 08:38:59 UTC
Idea for hint. Such a hint on line like "return new MyMain;" inside function could offer && generate phpdoc like this: 
/**
 * @return MyMain 
 */
function GetMyMain() {
	return new MyMain();
}

Then CC would works fine in case like: $instance2->| mentioned by reported (phpdoc like above is btw. hint for
workaround for Roti)
Comment 13 Tomasz Slota 2008-09-16 15:22:36 UTC
You need to use PHPDoc tags to get it working. There is a number of enhancement requests for improving type recognition for class members, e.g. issue 147195, we will not have time to do it for this coming release though.

The issue in its original scope has been fixed 


Comment 14 roti 2008-09-16 16:24:51 UTC
wow, it works with phpdoc!
Thanx!
Comment 15 Mikhail Matveev 2008-10-09 16:43:28 UTC
Verified