1--TEST--
2Test ord() function : usage variations - test values for $string argument
3--FILE--
4<?php
5
6/* Prototype  : int ord  ( string $string  )
7 * Description: Return ASCII value of character
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing ord() function: with unexpected inputs for 'string' argument ***\n";
12
13//get an unset variable
14$unset_var = 'string_val';
15unset($unset_var);
16
17//defining a class
18class sample  {
19  public function __toString() {
20    return "sample object";
21  }
22}
23
24//getting the resource
25$file_handle = fopen(__FILE__, "r");
26
27// array with different values for $input
28$inputs =  array (
29
30/*1*/	  0,
31		  1,
32		  255,
33		  256,
34		  2147483647,
35		  -2147483648,
36
37		  // float values
38/*7*/	  10.5,
39		  -20.5,
40		  10.1234567e10,
41
42		  // array values
43/*10*/	  array(),
44		  array(0),
45		  array(1, 2),
46
47		  // boolean values
48/*13*/	  true,
49		  false,
50		  TRUE,
51		  FALSE,
52
53		  // null values
54/*17*/	  NULL,
55		  null,
56
57		  // objects
58/*19*/	  new sample(),
59
60		  // resource
61/*20*/	  $file_handle,
62
63		  // undefined variable
64/*21*/	  @$undefined_var,
65
66		  // unset variable
67/*22*/	  @$unset_var
68);
69
70// loop through with each element of the $string array to test ord() function
71$count = 1;
72foreach($inputs as $input) {
73  echo "-- Iteration $count --\n";
74  var_dump( ord($input) );
75  $count ++;
76}
77
78fclose($file_handle);  //closing the file handle
79
80?>
81===DONE===
82--EXPECTF--
83*** Testing ord() function: with unexpected inputs for 'string' argument ***
84-- Iteration 1 --
85int(48)
86-- Iteration 2 --
87int(49)
88-- Iteration 3 --
89int(50)
90-- Iteration 4 --
91int(50)
92-- Iteration 5 --
93int(50)
94-- Iteration 6 --
95int(45)
96-- Iteration 7 --
97int(49)
98-- Iteration 8 --
99int(45)
100-- Iteration 9 --
101int(49)
102-- Iteration 10 --
103
104Warning: ord() expects parameter 1 to be string, array given in %s on line %d
105NULL
106-- Iteration 11 --
107
108Warning: ord() expects parameter 1 to be string, array given in %s on line %d
109NULL
110-- Iteration 12 --
111
112Warning: ord() expects parameter 1 to be string, array given in %s on line %d
113NULL
114-- Iteration 13 --
115int(49)
116-- Iteration 14 --
117int(0)
118-- Iteration 15 --
119int(49)
120-- Iteration 16 --
121int(0)
122-- Iteration 17 --
123int(0)
124-- Iteration 18 --
125int(0)
126-- Iteration 19 --
127int(115)
128-- Iteration 20 --
129
130Warning: ord() expects parameter 1 to be string, resource given in %s on line %d
131NULL
132-- Iteration 21 --
133int(0)
134-- Iteration 22 --
135int(0)
136===DONE===
137