Skip to content

Instantly share code, notes, and snippets.

@JanTvrdik
Created November 13, 2010 15:42
Show Gist options
  • Save JanTvrdik/675424 to your computer and use it in GitHub Desktop.
Save JanTvrdik/675424 to your computer and use it in GitHub Desktop.
<?php
class Foo
{
/**
* @return Foo|int|NULL|TRUE|FALSE|bool
*/
public function test()
{
}
}
$foo = new Foo();
$foo->test()->test(); // fails
<?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
}
<?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