In PHP, what is the differences between NULL and setting a string to equal 2 single quotes

后端 未结 5 1329
情歌与酒
情歌与酒 2020-11-30 05:06

I used to set things like this when I wanted blank values.

$blankVar = \'\';

Then after some months, I decided this looked better and had a

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 05:19

    Aside from the differences stated by Rex, there's two types of comparisons in PHP, loose and strict:

    http://www.php.net/manual/en/types.comparisons.php

    If strict comparisons or functions like is_null() are used in any capacity, you'll get different results. With loose comparisons, however, PHP is pretty lenient.

    I don't know for sure, but you may be able to use your null approach, then just typecast when you're using the variable in the context where you had issues (i.e. pass (string) $blankVar). If that works, it may mean less changes are necessary to your code.

提交回复
热议问题