1--TEST-- 2#[\Deprecated]: Throwing error handler. 3--FILE-- 4<?php 5 6set_error_handler(function (int $errno, string $errstr, ?string $errfile = null, ?int $errline = null) { 7 throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); 8}); 9 10#[\Deprecated("convert to exception")] 11function test() { 12 echo "Not executed", PHP_EOL; 13} 14 15try { 16 test(); 17} catch (ErrorException $e) { 18 echo "Caught: ", $e->getMessage(), PHP_EOL; 19} 20 21eval(<<<'CODE' 22 #[\Deprecated("convert to exception")] 23 function test2() { 24 echo "Not executed", PHP_EOL; 25 } 26CODE); 27 28try { 29 test2(); 30} catch (ErrorException $e) { 31 echo "Caught: ", $e->getMessage(), PHP_EOL; 32} 33 34class Clazz { 35 #[\Deprecated("convert to exception")] 36 function test() { 37 echo "Not executed", PHP_EOL; 38 } 39} 40 41try { 42 $cls = new Clazz(); 43 $cls->test(); 44} catch (ErrorException $e) { 45 echo "Caught: ", $e->getMessage(), PHP_EOL; 46} 47 48$closure = #[\Deprecated("convert to exception")] function () { 49 echo "Not executed", PHP_EOL; 50}; 51 52try { 53 $closure(); 54} catch (ErrorException $e) { 55 echo "Caught: ", $e->getMessage(), PHP_EOL; 56} 57 58class Constructor { 59 #[\Deprecated("convert to exception")] 60 public function __construct() { 61 echo "Not executed", PHP_EOL; 62 } 63} 64 65try { 66 new Constructor(); 67} catch (ErrorException $e) { 68 echo "Caught: ", $e->getMessage(), PHP_EOL; 69} 70 71class Destructor { 72 #[\Deprecated("convert to exception")] 73 public function __destruct() { 74 echo "Not executed", PHP_EOL; 75 } 76} 77 78try { 79 new Destructor(); 80} catch (ErrorException $e) { 81 echo "Caught: ", $e->getMessage(), PHP_EOL; 82} 83 84?> 85--EXPECTF-- 86Caught: Function test() is deprecated, convert to exception 87Caught: Function test2() is deprecated, convert to exception 88Caught: Method Clazz::test() is deprecated, convert to exception 89Caught: Function {closure:%s:%d}() is deprecated, convert to exception 90Caught: Method Constructor::__construct() is deprecated, convert to exception 91Caught: Method Destructor::__destruct() is deprecated, convert to exception 92