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 258226 - PHP method return value type-hinting doesn't work when the return type is a class from another namespace
Summary: PHP method return value type-hinting doesn't work when the return type is a c...
Status: VERIFIED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.2
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-03 11:49 UTC by BlameFate
Modified: 2016-03-07 11:02 UTC (History)
0 users

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 BlameFate 2016-03-03 11:49:36 UTC
NetBeans doesn't recognise the return type of class methods, or assist with code completion on values returned from such methods; when the return type is a class from another namespace.

For example:

<?php    namespace TEST;
class testClass{
	public function testMethod():\DateTime{
		return new \DateTime('now',new \DateTimeZone('UTC'));
	}
	public static function testStaticMethod():\DateTime{
		return new \DateTime('now',new \DateTimeZone('UTC'));
	}
}
$testInstance=new testClass();
echo($testInstance->testMethod()->format('Y-m-d H:i:s'));

echo(testClass::testStaticMethod()->format('Y-m-d H:i:s'));

---

Expected behavior: On typing:   echo(test1::test3()->
- NetBeans should drop down a list of class member variable & method options to assist with code autocompletion.
Actual behavior: NetBeans drops down a standard autocomplete list that's full of complete nonsense, and doesn't have any of the class members/methods from the test1 class in it.

PHP5.6 / 7 seems to have no problem with my code (it runs as expected, and generates the expected results), but NetBeans doesn't like it! Fixing this issue would make programming PHP in NetBeans much more convenient for me.

See Also: This other bug is similar in some ways, but technically different:
https://netbeans.org/bugzilla/show_bug.cgi?id=193356
Comment 1 BlameFate 2016-03-03 11:52:46 UTC
Of course, I really meant to write:
$testInstance->testMethod()->
testClass::testStaticMethod()->
- There is no autocompletion when you type these!
Comment 2 Tomas Mysik 2016-03-04 07:34:42 UTC
Should be fixed now, please verify.

http://hg.netbeans.org/web-main/rev/8f8b50dac241

BTW please note that PHP7 is not (yet) officially supported by NetBeans so if you want to test its current (far from perfect) state, start NetBeans from command line with this property [1].

Thanks.
[1] -J-Dnb.php7=true
Comment 3 BlameFate 2016-03-04 13:01:43 UTC
Thank you for your prompt attention! I've been using the nightly builds for their partial support of PHP7, which is much better than PHP7 support in the "latest stable" build of NetBeans.

I tried the latest nightly build: 201603040002 - this does NOT appear to resolve the issue! (I tried amending the Windows shortcut:
"C:\Program Files\NetBeans Dev 201603040002\bin\netbeans.exe" -J-Dnb.php7=true

I also tried from the command line as you suggested: I get the same results, it's still broken.

Should I wait until tomorrow for the next "Nightly Build", before trying again? Or next week?
Comment 4 Tomas Mysik 2016-03-04 13:08:21 UTC
Just wait for a message that will automatically appear here as a comment saying in which daily build the fix will be available. Do not forget to use nb.php7 property as described in my previous comment.

Thanks.
Comment 5 Quality Engineering 2016-03-05 02:28:24 UTC
Integrated into 'main-silver', will be available in build *201603050002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/8f8b50dac241
User: Tomas Mysik <tmysik@netbeans.org>
Log: #258226 - PHP method return value type-hinting doesn't work when the return type is a class from another namespace
Comment 6 BlameFate 2016-03-07 10:57:22 UTC
Just tested Nightly Build 201603070002, with the nb7 property you described! This is working nicely. Thank you for your advice, and for your prompt work in resolving this issue/ implementing this feature!

Windows 10 users: Visit this "folder" (directory):
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\NetBeans
Then find a "shortcut" that looks like this:
NetBeans IDE Build 201603070002
Right click (context menu), open "Properties", change "Target" to something like this:
"C:\Program Files\NetBeans Dev 201603070002\bin\netbeans.exe" -J-Dnb.php7=true
Comment 7 Tomas Mysik 2016-03-07 11:02:28 UTC
Thanks for verification and your positive feedback! :)