global statement removal: hphp/test/zend [2/x]
[hiphop-php.git] / hphp / test / zend / good / ext / iconv / tests / iconv_strpos_variation2.php
blob87f0b9e25f806f6e3d418cac44e20bc1a14fce07
1 <?php
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 $needle arg to test behaviour
9 */
11 echo "*** Testing iconv_strpos() : usage variations ***\n";
13 // Initialise function arguments not being substituted
14 $haystack = 'string_val';
15 $offset = 0;
16 $encoding = 'utf-8';
18 //get an unset variable
19 $unset_var = 10;
20 unset ($unset_var);
22 // get a class
23 class classA
25 public function __toString() {
26 return "Class A object";
30 // heredoc string
31 $heredoc = <<<EOT
32 hello world
33 EOT;
35 // get a resource variable
36 $fp = fopen(__FILE__, "r");
38 // unexpected values to be passed to $needle argument
39 $inputs = array(
41 // int data
42 /*1*/ 0,
44 12345,
45 -2345,
47 // float data
48 /*5*/ 10.5,
49 -10.5,
50 12.3456789000e10,
51 12.3456789000E-10,
52 .5,
54 // null data
55 /*10*/ NULL,
56 null,
58 // boolean data
59 /*12*/ true,
60 false,
61 TRUE,
62 FALSE,
64 // empty data
65 /*16*/ "",
66 '',
68 // string data
69 /*18*/ "string",
70 'string',
71 $heredoc,
73 // object data
74 /*21*/ new classA(),
76 // undefined data
77 /*22*/ @$undefined_var,
79 // unset data
80 /*23*/ @$unset_var,
82 // resource variable
83 /*24*/ $fp
86 // loop through each element of $inputs to check the behavior of iconv_strpos()
87 $iterator = 1;
88 foreach($inputs as $input) {
89 echo "\n-- Iteration $iterator --\n";
90 try { var_dump( iconv_strpos($haystack, $input, $offset, $encoding)); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
91 $iterator++;
94 fclose($fp);
96 echo "Done";