This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo | |
{ | |
/** | |
* @return Foo|int|NULL|TRUE|FALSE|bool | |
*/ | |
public function test() | |
{ | |
} | |
} | |
$foo = new Foo(); | |
$foo->test()->test(); // fails |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Alpha | |
{ | |
class Foo | |
{ | |
public function testA() {} | |
} | |
/** | |
* @property Foo $c | |
*/ | |
class TestClass | |
{ | |
/** @var \Alpha\Foo */ | |
public $a; | |
/** @var Foo */ | |
public $b; | |
/** | |
* @return Foo | |
*/ | |
public function method() | |
{ | |
} | |
public function method2() | |
{ | |
return new Foo; | |
} | |
} | |
$testClass = new TestClass(); | |
$testClass->a->testA(); // OK | |
$testClass->b->testA(); // OK | |
$testClass->c->testA(); // OK | |
$testClass->method()->testA(); // OK | |
$testClass->method2()->testA(); // OK | |
} | |
namespace Beta | |
{ | |
class Foo | |
{ | |
public function testB() {} | |
} | |
class Child extends \Alpha\TestClass {} | |
$child = new Child(); | |
$child->a->testA(); // OK | |
$child->b->testA(); // OK | |
$child->c->testA(); // fails – suggests testB instead of testA | |
$child->method()->testA(); // OK | |
$child->method2()->testA(); // fails – suggests testB instead of testA | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Alpha | |
{ | |
class Foo | |
{ | |
public function test() {} | |
} | |
} | |
namespace Beta | |
{ | |
use Alpha as NamespaceAlias; | |
use Alpha\Foo as ClassAlias; | |
class TestClass | |
{ | |
public function methodA() | |
{ | |
return new \Alpha\Foo(); | |
} | |
public function methodB() | |
{ | |
return new ClassAlias; | |
} | |
public function methodC() | |
{ | |
return new NamespaceAlias\Foo(); | |
} | |
} | |
$testClass = new TestClass(); | |
$testClass->methodA()->test(); // OK | |
$testClass->methodB()->test(); // OK | |
$testClass->methodC()->test(); // OK | |
} | |
namespace Gamma | |
{ | |
class Child extends \Beta\TestClass {} | |
$child = new Child(); | |
$child->methodA()->test(); // OK | |
$child->methodB()->test(); // fails | |
$child->methodC()->test(); // fails | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment