<?php
function sayHello(string $name): never
{
echo "Hello, $name";
exit(); // if we comment this line, php throws fatal error
}
sayHello("John"); // result: "Hello, John"never ăŻă é˘ć°ăćťăŁăŚăăŞăăă¨ă示ăćťăĺ¤ăŽĺă§ăă ăăăŻăé˘ć°ăŽä¸ă§ exit() ăăłăźăŤăăăăă äžĺ¤ăăšăăźăăăăă çĄéăŤăźăăŤĺ ĽăăăŽăăăăă§ăăăă¨ăćĺłăăžăă ăăŁăŚăăăŽĺ㯠union ĺ ăŽä¸é¨ă¨ăăŚćĺŽăăăă¨ăĺşćĽăžăăă PHP 8.1.0 䝼éă§ĺŠç¨ă§ăăžăă
never ăŻă ĺçčŤăŽç¨čŞă§č¨ăă¨ăăăă ĺăŤăăăăžăă ă¤ăžăăĺ ¨ăŚăŽäťăŽĺăŽé¨ĺĺă§ăăă çśćżăăéăŤäťăŽćťăĺ¤ăŽĺă罎ăćăăăă¨ăă§ăăžăă
<?php
function sayHello(string $name): never
{
echo "Hello, $name";
exit(); // if we comment this line, php throws fatal error
}
sayHello("John"); // result: "Hello, John"I think the description should be corrected from return-only to non-return function since the context is now misleadingNever cannot be used in a union type because, being the bottom type, it is already automatically a subtype of every other type. "A|never" is equivalent to "A".
When one type is "obviously" a subtype of another (i.e., it doesn't require loading the class definitions of all the types involved), the former is redundant in union types, and PHP flags the union of both as an error.
Similarly for intersection types, where "A&never" means the same thing as "never". It "obviously" doesn't make sense to mention A there, so PHP won't allow doing so.