Deepak Rai
Deepak Rai

Reputation: 164

How To resolve !empty function issue in php 5.4

I used !empty function multiple places. But It not woring on php 5.4. It giving error can not use return type context. So I create a function for checking null values in php.

function not_empty($value) {
    if(trim($value)==null or trim($value) == '0' or trim($value)=="0"){
        return false;
    }
    else{
        return true;
    }
}

So Can I use This Instead of !empty in my project.

Upvotes: 0

Views: 1306

Answers (1)

Nirpendra Patel
Nirpendra Patel

Reputation: 679

The following things are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)

so no way you can consider your statement to be anywhere close to !empty in php

What you are doing is equivalent only to first condition i.e., empty string. and also null too. But not false and 0.

I hope u got it

Upvotes: 2

Related Questions