hiphop-php /hphp/test/zend/bad/ext/standard/tests/general_functions/is_null.php

Language PHP Lines 140
MD5 Hash 9555ffd82ec6b597fefae9388863b02c Estimated Cost $2,484 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/* Prototype: bool is_null ( mixed $var );
 * Description: Finds whether the given variable is NULL 
 */

echo "*** Testing is_null() with valid null values ***\n";
// different valid  null vlaues 
$unset_array = array();
$unset_int = 10;
$unset_float = 10.5;
$unset_bool = true;
$unset_object = new stdclass;
$unset_resource = fopen(__FILE__, "r");
// unset them to make it null.
unset ($unset_array, $unset_int, $unset_float, $unset_bool, $unset_object, $unset_resource); 
$null_var1 = NULL;
$null_var2 = null;

$valid_nulls = array(
  NULL,
  null,
  @$null_var1,
  @$null_var2,
  @$unset_array,
  @$unset_int,
  @$unset_float,
  @$unset_bool,
  @$unset_object,
  @$unset_resource,
  @$undefined_var,
);
/* loop to check that is_null() recognizes different 
   null values, expected output: bool(true) */
$loop_counter = 1;
foreach ($valid_nulls as $null_val ) {
  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  var_dump( is_null($null_val) );
}

echo "\n*** Testing is_bool() on non null values ***\n";

// get a resource type variable
$fp = fopen (__FILE__, "r");
$dfp = opendir ( dirname(__FILE__) );

// other types in a array 
$not_null_types = array (
/* integers */
  0,
  1,
  -1,
  -0,
  543915,
  -5322,
  0x0,
  0x1,
  0x55F,
  -0xCCF,
  0123,
  -0654,
  00,
  01,

  /* strings */
  "",
  '',
  "0",
  '0',
  "1",
  '1',
  'string',
  "string",
  "true",
  "false",
  "FALSE",
  "TRUE",
  'true',
  'false',
  'FALSE',
  'TRUE',
  "NULL",
  "null",

  /* floats */
  0.0,
  1.0,
  -1.0,
  10.0000000000000000005,
  .5e6,
  -.5E7,
  .5E+8,
  -.5e+90,
  1e5,
  -1e5,
  1E5,
  -1E7,

  /* objects */
  new stdclass,

  /* resources */
  $fp,
  $dfp,

  /* arrays */
  array(),
  array(0),
  array(1),
  array(NULL),
  array(null),
  array("string"),
  array(true),
  array(TRUE),
  array(false),
  array(FALSE),
  array(1,2,3,4),
  array(1 => "One", "two" => 2),
);
/* loop through the $not_null_types to see working of 
   is_null() on non null types, expected output: bool(false) */
$loop_counter = 1;
foreach ($not_null_types as $type ) {
  echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  var_dump( is_null($type) );
}

echo "\n*** Testing error conditions ***\n";
//Zero argument
var_dump( is_null() );

//arguments more than expected 
var_dump( is_null(NULL, null) );
 
echo "Done\n";

// close the resources used
fclose($fp);
closedir($dfp);

?>
Back to Top