]> granicus.if.org Git - php/blob
a363e26f24
[php] /
1 --TEST--
2 Test 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
10 echo "*** Testing strval() : error conditions ***\n";
11
12 error_reporting(E_ALL ^ E_NOTICE);
13
14 class MyClass
15 {
16     // no toString() method defined
17 }
18
19 // Testing strval with a object which has no toString() method
20 echo "\n-- Testing strval() function with object which has not toString() method  --\n";
21 try {
22     var_dump( strval(new MyClass()) );
23 } catch (Error $e) {
24     echo $e->getMessage(), "\n";
25 }
26
27 ?>
28 --EXPECTF--
29 *** Testing strval() : error conditions ***
30
31 -- Testing strval() function with object which has not toString() method  --
32 Object of class MyClass could not be converted to string