1--TEST--
2Test bin2hex() function : usage variations - test values for $str argument
3--FILE--
4<?php
5
6/* Prototype  : string bin2hex  ( string $str  )
7 * Description: Convert binary data into hexadecimal representation
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing bin2hex() function: with unexpected inputs for 'str' 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	  // integer values
31/*1*/ 0,
32	  1,
33	  123456,
34
35	  // float values
36/*4*/ 10.5,
37	  -20.5,
38	  10.1234567e10,
39
40	  // array values
41/*7*/ array(),
42	  array(0),
43	  array(1, 2),
44
45	  // boolean values
46/*10*/true,
47	  false,
48	  TRUE,
49	  FALSE,
50
51	  // null values
52/*14*/NULL,
53	  null,
54
55	  // objects
56/*16*/new sample(),
57
58	  // resource
59/*17*/$file_handle,
60
61	  // undefined variable
62/*18*/@$undefined_var,
63
64	  // unset variable
65/*19*/@$unset_var
66);
67
68// loop through with each element of the $inputs array to test bin2hex() function
69$count = 1;
70foreach($inputs as $input) {
71  echo "-- Iteration $count --\n";
72  var_dump(bin2hex($input) );
73  $count ++;
74}
75
76fclose($file_handle);  //closing the file handle
77
78?>
79===DONE===
80--EXPECTF--
81*** Testing bin2hex() function: with unexpected inputs for 'str' argument ***
82-- Iteration 1 --
83string(2) "30"
84-- Iteration 2 --
85string(2) "31"
86-- Iteration 3 --
87string(12) "313233343536"
88-- Iteration 4 --
89string(8) "31302e35"
90-- Iteration 5 --
91string(10) "2d32302e35"
92-- Iteration 6 --
93string(24) "313031323334353637303030"
94-- Iteration 7 --
95
96Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
97NULL
98-- Iteration 8 --
99
100Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
101NULL
102-- Iteration 9 --
103
104Warning: bin2hex() expects parameter 1 to be string, array given in %s on line %d
105NULL
106-- Iteration 10 --
107string(2) "31"
108-- Iteration 11 --
109string(0) ""
110-- Iteration 12 --
111string(2) "31"
112-- Iteration 13 --
113string(0) ""
114-- Iteration 14 --
115string(0) ""
116-- Iteration 15 --
117string(0) ""
118-- Iteration 16 --
119string(26) "73616d706c65206f626a656374"
120-- Iteration 17 --
121
122Warning: bin2hex() expects parameter 1 to be string, resource given in %s on line %d
123NULL
124-- Iteration 18 --
125string(0) ""
126-- Iteration 19 --
127string(0) ""
128===DONE===
129