Preemptively update tests for UndefinedVariableException 3/n
[hiphop-php.git] / hphp / test / zend / good / ext / iconv / tests / iconv_strrpos_variation3.php
blob1c4e3125e6b7e30024a3330aec684f83de034c23
1 <?hh
2 /* Prototype : proto int iconv_strrpos(string haystack, string needle [, string charset])
3 * Description: Find position of last occurrence of a string within another
4 * Source code: ext/iconv/iconv.c
5 */
7 /*
8 * Pass iconv_strrpos() different data types as $encoding argument to test behaviour
9 * Where possible 'UTF-8' has been entered as a string value
12 // get a class
13 class classA
15 public function __toString() {
16 return "UTF-8";
19 <<__EntryPoint>> function main(): void {
20 echo "*** Testing iconv_strrpos() : usage variations ***\n";
22 // Initialise function arguments not being substituted
23 $haystack = b'hello, world';
24 $needle = b'world';
27 // heredoc string
28 $heredoc = <<<EOT
29 UTF-8
30 EOT;
32 // get a resource variable
33 $fp = fopen(__FILE__, "r");
35 // unexpected values to be passed to $encoding argument
36 $inputs = varray[
38 // int data
39 /*1*/ 0,
41 12345,
42 -2345,
44 // float data
45 /*5*/ 10.5,
46 -10.5,
47 12.3456789000e10,
48 12.3456789000E-10,
49 .5,
51 // null data
52 /*10*/ NULL,
53 null,
55 // boolean data
56 /*12*/ true,
57 false,
58 TRUE,
59 FALSE,
61 // empty data
62 /*16*/ "",
63 '',
65 // string data
66 /*18*/ "UTF-8",
67 'UTF-8',
68 $heredoc,
70 // object data
71 /*21*/ new classA(),
75 // resource variable
76 /*22*/ $fp
79 // loop through each element of $inputs to check the behavior of iconv_strrpos()
80 $iterator = 1;
81 foreach($inputs as $input) {
82 echo "\n-- Iteration $iterator --\n";
83 try { var_dump( iconv_strrpos($haystack, $needle, $input)); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
84 $iterator++;
87 fclose($fp);
89 echo "Done";