Skip to content

Commit 9e9cd9a

Browse files
committed
fix empty
1 parent f0464b6 commit 9e9cd9a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

php.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,9 @@ func Glob(pattern string) ([]string, error) {
16291629

16301630
// Empty empty()
16311631
func Empty(val interface{}) bool {
1632+
if val == nil {
1633+
return true
1634+
}
16321635
v := reflect.ValueOf(val)
16331636
switch v.Kind() {
16341637
case reflect.String, reflect.Array:

php_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ func TestVariable(t *testing.T) {
308308

309309
tIsNumeric = IsNumeric("123456")
310310
equal(t, true, tIsNumeric)
311+
312+
equal(t, true, Empty(nil))
313+
equal(t, true, Empty(false))
314+
equal(t, true, Empty(0))
315+
equal(t, true, Empty(""))
316+
equal(t, true, Empty(0.0))
317+
equal(t, true, Empty([]int{}))
318+
equal(t, true, Empty([0]int{}))
319+
equal(t, false, Empty([1]int{}))
320+
equal(t, true, Empty(map[int]int{}))
311321
}
312322

313323
func TestProgramExecution(t *testing.T) {

0 commit comments

Comments
 (0)