Skip to content

Instantly share code, notes, and snippets.

@SpacefulSpecies
Last active August 29, 2015 14:15
Show Gist options
  • Save SpacefulSpecies/2684f62675630978dbff to your computer and use it in GitHub Desktop.
Save SpacefulSpecies/2684f62675630978dbff to your computer and use it in GitHub Desktop.
Phpstorm 8.0.3: Typehint error with nullable static
<?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