hiphop-php /hphp/test/spec/tests/expressions/primary_expressions/intrinsics_empty.php

Language PHP Lines 155
MD5 Hash 2f2147a38aaf4c2dec113ffabdf63abc Estimated Cost $2,408 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php

/*
   +-------------------------------------------------------------+
   | Copyright (c) 2015 Facebook, Inc. (http://www.facebook.com) |
   +-------------------------------------------------------------+
*/

error_reporting(-1);

include_once 'Point.inc';

echo "--------- TRUE -------------\n";

var_dump(empty(TRUE));
$v = TRUE;
var_dump(empty($v));

echo "--------- FALSE -------------\n";

var_dump(empty(FALSE));
$v = FALSE;
var_dump(empty($v));

echo "--------- -10 -------------\n";

var_dump(empty(-10));
$v = -10;
var_dump(empty($v));

echo "---------- 0 ------------\n";

var_dump(empty(0));
$v = 0;
var_dump(empty($v));

echo "---------- 123 ------------\n";

var_dump(empty(123));
$v = 123;
var_dump(empty($v));

echo "--------- -10.56 -------------\n";

var_dump(empty(-10.56));
$v = -10.56;
var_dump(empty($v));

echo "--------- 0.0 -------------\n";

var_dump(empty(0.0));
$v = 0.0;
var_dump(empty($v));

echo "-------- 123.456 --------------\n";

var_dump(empty(123.456));
$v = 123.456;
var_dump(empty($v));

echo "--------- NULL -------------\n";

var_dump(empty(NULL));
$v = NULL;
var_dump(empty($v));

echo "---------- \"\" ------------\n";

var_dump(empty(""));
$v = "";
var_dump(empty($v));

echo "---------- \"0\" ------------\n";

var_dump(empty("0"));
$v = "0";
var_dump(empty($v));

echo "---------- \"00\" ------------\n";

var_dump(empty("00"));
$v = "00";
var_dump(empty($v));

echo "--------- \"Hello\" -------------\n";

var_dump(empty("Hello"));
$v = "Hello";
var_dump(empty($v));

echo "--------- [] -------------\n";

var_dump(empty([]));
$v = [];
var_dump(empty($v));

echo "---------- [10, 20] ------------\n";

var_dump(empty([10, 20]));
$v = [10, 20];
var_dump(empty($v));

echo "--------- Point(3, 5) -------------\n";

$v = new Point(3, 5);
var_dump(empty($v));

echo "--------- instance of class having no properties -------------\n";

class XX {}
$v = new XX;
var_dump(empty($v));

echo "--------- undefined parameter -------------\n";

function f($p)
{
    var_dump($p);
    var_dump(empty($p));
}

f();
f(NULL);
f(10);

echo "---------- resource STDIN ------------\n";

var_dump(empty(STDIN));
$v = STDIN;
var_dump(empty($v));

echo "---------- dynamic property ------------\n";

class X1
{
}

class X2
{
    public function __isset($name)
    {
        echo "Inside " . __METHOD__ . " with \$name $name\n";
//      return FALSE;
        return TRUE;
    }
}

$x1 = new X1;
var_dump(empty($x1->m));
$x1->m = 123;
var_dump(empty($x1->m));

$x2 = new X2;
var_dump(empty($x2->m));
Back to Top