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

https://github.com/symfony/symfony/blob/7c026bb33e8ca96b285402f7fe7ae27a04a74ea9/src/symfony/component/httpfoundation/session/storage/nativesessionstorage.php#l99

is defined in source, no type hint

public function __construct(array $options = array(), $handler = null, metadatabag $metabag = null) 

https://github.com/symfony/symfony/blob/7c026bb33e8ca96b285402f7fe7ae27a04a74ea9/src/symfony/component/httpfoundation/session/storage/nativesessionstorage.php#l353

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

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -