Last active
August 29, 2015 14:15
-
-
Save SpacefulSpecies/2684f62675630978dbff to your computer and use it in GitHub Desktop.
Phpstorm 8.0.3: Typehint error with nullable static
This file contains hidden or 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 | |
// Simple late static binding example | |
class A | |
{ | |
/** | |
* @return static | |
*/ | |
public static function create() | |
{ | |
return new static(); | |
} | |
} | |
class B extends A {} | |
// Simple function to test the typehinting of nullable B | |
function requireBOrNull(B $b = null) {} | |
// When $b can either be B or null, phpstorm gives an error on typehinting | |
if (isset($someCondition)) { | |
$b = B::create(); | |
} else { | |
$b = null; | |
} | |
requireBOrNull($b); // phpstorm error: Expected B, got static (Invocation parameter types are not compatible with declared.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment