php - Symfony's documentation Implies that Multiple Type-Hinting is Possible. Why? -
i had assumed multiple type-hinting wasn't possible. however, saw constructor in symfony api documentation documentation.
__construct(array $options = array(), abstractproxy|nativesessionhandler|sessionhandlerinterface|null $handler = null, metadatabag $metabag = null)
for second parameter, makes seemthat multiple types possible. can explain seeing?
its question, though answer not type hint in language sense. more of documentation
is defined in source, no type hint
public function __construct(array $options = array(), $handler = null, metadatabag $metabag = null)
is functionality exists, checks instanceof of type hints listed in documentation
if (!$savehandler instanceof abstractproxy && !$savehandler instanceof nativesessionhandler && !$savehandler instanceof \sessionhandlerinterface && null !== $savehandler) { throw new \invalidargumentexception('must instance of abstractproxy or nativesessionhandler; implement \sessionhandlerinterface; or null.'); }
these hints used ide's consistency checking code, pazi mentioned in comments
more information can found here
http://www.phpdoc.org/docs/latest/guides/types.html
to able track types may used in value can use pipe, or or, (|) operator separate each type associated value may be.
in following example method, or function, return either string or null value:
/** @return string|null */ ides recognize format , offer auto-completion
Comments
Post a Comment