1--TEST-- 2Test strval() function : usage variations - error conditions 3--FILE-- 4<?php 5/* Prototype : string strval ( mixed $var ) 6 * Description: Get the string value of a variable. 7 * Source code: ext/standard/string.c 8 */ 9 10echo "*** Testing strval() : error conditions ***\n"; 11 12error_reporting(E_ALL ^ E_NOTICE); 13 14class MyClass 15{ 16 // no toString() method defined 17} 18 19$string = "Hello"; 20$extra_arg = 10; 21 22//Test strval with one more than the expected number of arguments 23echo "\n-- Testing strval() function with more than expected no. of arguments --\n"; 24var_dump( strval($string, $extra_arg) ); 25 26// Testing strval with one less than the expected number of arguments 27echo "\n-- Testing strval() function with less than expected no. of arguments --\n"; 28var_dump( strval() ); 29 30// Testing strval with a object which has no toString() method 31echo "\n-- Testing strval() function with object which has not toString() method --\n"; 32try { 33 var_dump( strval(new MyClass()) ); 34} catch (Error $e) { 35 echo $e->getMessage(), "\n"; 36} 37 38?> 39===DONE=== 40--EXPECTF-- 41*** Testing strval() : error conditions *** 42 43-- Testing strval() function with more than expected no. of arguments -- 44 45Warning: strval() expects exactly 1 parameter, 2 given in %s on line %d 46NULL 47 48-- Testing strval() function with less than expected no. of arguments -- 49 50Warning: strval() expects exactly 1 parameter, 0 given in %s on line %d 51NULL 52 53-- Testing strval() function with object which has not toString() method -- 54Object of class MyClass could not be converted to string 55===DONE=== 56