Preemptively update tests for UndefinedVariableException 3/n
[hiphop-php.git] / hphp / test / zend / good / ext / iconv / tests / iconv_strpos_variation1.php
blob9906a732e02d193b608a9fc56dcafd3e3c406259
1 <?hh
2 /* Prototype : int iconv_strpos(string haystack, string needle [, int offset [, string charset]])
3 * Description: Find position of first occurrence of a string within another
4 * Source code: ext/iconv/iconv.c
5 */
7 /*
8 * Pass iconv_strpos different data types as $haystack arg to test behaviour
9 */
11 // get a class
12 class classA
14 public function __toString() {
15 return "Class A object";
18 <<__EntryPoint>> function main(): void {
19 echo "*** Testing iconv_strpos() : usage variations ***\n";
21 // Initialise function arguments not being substituted
22 $needle = 'string_val';
23 $offset = 0;
24 $encoding = 'utf-8';
27 // heredoc string
28 $heredoc = <<<EOT
29 hello world
30 EOT;
32 // get a resource variable
33 $fp = fopen(__FILE__, "r");
35 // unexpected values to be passed to $haystack 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*/ "string",
67 'string',
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_strpos()
80 $iterator = 1;
81 foreach($inputs as $input) {
82 echo "\n-- Iteration $iterator --\n";
83 try { var_dump( iconv_strpos($input, $needle, $offset, $encoding)); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
84 $iterator++;
87 fclose($fp);
89 echo "Done";