1--TEST-- 2ReflectionMethod constructor errors 3--CREDITS-- 4Robin Fernandes <robinf@php.net> 5Steve Seear <stevseea@php.net> 6--FILE-- 7<?php 8 9class TestClass 10{ 11 public function foo() { 12 } 13} 14 15 16try { 17 echo "Too few arguments:\n"; 18 $methodInfo = new ReflectionMethod(); 19} catch (ArgumentCountError $re) { 20 echo "Ok - ".$re->getMessage().PHP_EOL; 21} 22try { 23 echo "\nToo many arguments:\n"; 24 $methodInfo = new ReflectionMethod("TestClass", "foo", true); 25} catch (ArgumentCountError $re) { 26 echo "Ok - ".$re->getMessage().PHP_EOL; 27} 28 29 30try { 31 //invalid class 32 $methodInfo = new ReflectionMethod("InvalidClassName", "foo"); 33} catch (ReflectionException $re) { 34 echo "Ok - ".$re->getMessage().PHP_EOL; 35} 36 37 38try { 39 //invalid 1st param 40 $methodInfo = new ReflectionMethod([], "foo"); 41} catch (TypeError $re) { 42 echo "Ok - ".$re->getMessage().PHP_EOL; 43} 44 45try{ 46 //invalid 2nd param 47 $methodInfo = new ReflectionMethod("TestClass", []); 48} catch (TypeError $re) { 49 echo "Ok - ".$re->getMessage().PHP_EOL; 50} 51 52?> 53--EXPECT-- 54Too few arguments: 55Ok - ReflectionMethod::__construct() expects at least 1 argument, 0 given 56 57Too many arguments: 58Ok - ReflectionMethod::__construct() expects at most 2 arguments, 3 given 59Ok - Class "InvalidClassName" does not exist 60Ok - ReflectionMethod::__construct(): Argument #1 ($objectOrMethod) must be of type object|string, array given 61Ok - ReflectionMethod::__construct(): Argument #2 ($method) must be of type ?string, array given 62