1--TEST-- 2never return type: acceptable covariance cases 3--FILE-- 4<?php 5 6class A 7{ 8 public function foo(): string 9 { 10 return "hello"; 11 } 12 13 public function bar(): never 14 { 15 throw new UnexpectedValueException('parent'); 16 } 17 18 public function &baz() 19 { 20 } 21 22 public function someReturningStaticMethod() : static 23 { 24 } 25} 26 27class B extends A 28{ 29 public function foo(): never 30 { 31 throw new UnexpectedValueException('bad'); 32 } 33 34 public function bar(): never 35 { 36 throw new UnexpectedValueException('child'); 37 } 38 39 public function &baz(): never 40 { 41 throw new UnexpectedValueException('child'); 42 } 43 44 public function someReturningStaticMethod(): never 45 { 46 throw new UnexpectedValueException('child'); 47 } 48} 49 50try { 51 (new B)->foo(); 52} catch (UnexpectedValueException $e) { 53 // do nothing 54} 55 56try { 57 (new B)->bar(); 58} catch (UnexpectedValueException $e) { 59 // do nothing 60} 61 62try { 63 (new B)->baz(); 64} catch (UnexpectedValueException $e) { 65 // do nothing 66} 67 68try { 69 (new B)->someReturningStaticMethod(); 70} catch (UnexpectedValueException $e) { 71 // do nothing 72} 73 74echo "OK!", PHP_EOL; 75 76?> 77--EXPECT-- 78OK! 79