monk
(Narshon)
September 28, 2013, 9:10am
1
I need help to differentiate between 0 and NULL values on Yii 1.1.8 models. Apparently, when an integer field in mysql is set to NULL, Yii returns 0 instead. I wonder if Yii converts the NULL value to 0 automatically? This should not be the case as 0 is not necessarily NULL. Please help.
softark
(Softark)
September 28, 2013, 1:36pm
2
Hi monk,
PHP uses implicit type conversion frequently.
$value = NULL;
if ($value == 0) {
echo 'Yes, it is zero. Ah, well, kind of ...';
}
Isn’t it because you are comparing the value with the operator ‘==’ ?
monk
(Narshon)
September 28, 2013, 1:51pm
3
This has worked now. So sorry I was quick to raise it here. It was my fault I hadn’t checked the data that was coming from mysql quite well.
monk
(Narshon)
September 28, 2013, 1:53pm
4
Yes, I was using ‘==’ instead of checking for equality using ‘===’.
This works now. thanks.
softark
(Softark)
September 28, 2013, 2:06pm
5
Don’t be sorry, no problem.
function is_empty($input){
return strlen((string)trim($input)) != 0 && empty($input);
}
if $input have any thing return True else if have NULL or null or ‘’ return false