Bug 510475 - PHP 7 return type overrides the return type set in PHPDoc
Summary: PHP 7 return type overrides the return type set in PHPDoc
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-14 17:52 EST by Claudio Luis CLA
Modified: 2020-05-14 10:17 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Luis CLA 2017-01-14 17:52:21 EST
With PHP 7, return types can be defined in the code itself to enforce it.

However the PHPDoc return type should still supersede the return type enforced by the function or method itself, and that's not the behavior Eclipse is displaying at the moment.

For example, let the classes, Foo and Bar, be defined as the following:

<?php
class Foo
{
	/**
	 * @return static
	 */
	public static function getNew() : Foo
	{
		$class = static::class;
		return new $class;
	}
}

class Bar extends Foo
{
	/**
	 * @return void
	 */
	public function doStuff() : void
	{
		...
	}
}
?>

When using:
<?php

$bar = Bar::getNew();
$bar->|  

The expected code completion suggestions here should be every public constant, property and method available on class Bar, thus in this case it should display both the getNew and doStuff methods to auto-complete.

However it only shows up the Foo ones, in other words, just the getNew method.

By dropping the ": Foo" return type from the method itself, as so:
/**
 * @return static
 */
public static function getNew()
{
	...
}

Then it starts showing the correct code suggestions from class Bar.


This was reproduced in:
Version: Neon.2 Release (4.6.2)
Build id: 20161208-0600