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

Summary: Type hinting for returned array of objects doesn't work if the function is called as foreach param
Product: php Reporter: therefromhere <therefromhere>
Component: EditorAssignee: Ondrej Brejla <obrejla>
Status: RESOLVED FIXED    
Severity: normal CC: Arvenil, GigAHerZ, mrugendrabhure, therefromhere
Priority: P3    
Version: 7.1   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

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