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 207589 - Type hinting for returned array of objects doesn't work if the function is called as foreach param
Summary: Type hinting for returned array of objects doesn't work if the function is ca...
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.1
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
: 180593 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-01-20 22:28 UTC by therefromhere
Modified: 2012-04-17 09:21 UTC (History)
4 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description therefromhere 2012-01-20 22:28:04 UTC
Type hinting of a method or function returning an array of objects doesn't work if the call is in a foreach block.

Sample code:

class myClass {  
    /**
     * @return myClass[]
     */
    public function retObjArray() 
    {
        return array(new myClass());
    }
    
    public function testHinting()
    {
        $myArr = $this->retObjArray();

        foreach ($myArr as $a)
        {
            $a->otherFunc(); // myClass type hinting works here (yay!)
        }
        
        foreach ($this->retObjArray() as $b)
        {
            $b-> // myClass type hinting doesn't work here
        }
    }
}
Comment 1 therefromhere 2012-01-20 22:29:24 UTC
PS, this is seen in Nightly build 201201180601.
Comment 2 Ondrej Brejla 2012-01-23 09:10:37 UTC
Yes, we don't support it right now...I'll look at it later. Thanks for your interrest!
Comment 3 Ondrej Brejla 2012-01-23 09:12:31 UTC
*** Bug 180593 has been marked as a duplicate of this bug. ***
Comment 4 Arvenil 2012-03-29 14:01:26 UTC
There is huge interest in this feature on stackoverflow:
http://stackoverflow.com/questions/778564/phpdoc-type-hinting-for-array-of-objects
Comment 5 Ondrej Brejla 2012-04-17 09:21:07 UTC
Fixed in web-main #b157fe1792d0 together with an issue #204104