0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHP, Ruby の null, blank 判定比較早見表

Posted at

PHP, Ruby の null, blank 判定比較早見表

nil? empty? blank? isset is_null empty if($var)
未定義 NameError NameError NameError false Undefined Undefined Undefined
$var = nil, null TRUE NoMethodError TRUE false TRUE TRUE false
$var = true false NoMethodError false TRUE false false TRUE
$var = false false NoMethodError TRUE TRUE false TRUE false
$var = [] false TRUE TRUE TRUE false TRUE false
$var = [1] false false false TRUE false false TRUE
$var = "" false TRUE TRUE TRUE false TRUE false
$var = " " false false TRUE TRUE false false TRUE
$var = 0 false NoMethodError false TRUE false TRUE false
$var = 1 false NoMethodError false TRUE false false TRUE
$var = "0" false false false TRUE false TRUE false
$var = "1" false false false TRUE false false TRUE

present?!blank?と同義なので省略
nil?is_nullの違いはなし
Ruby#empty?PHP#emptyは数値判定に誤差がある
PHPにblank?に当たる関数はないが、やはりemptyとは数値判定に誤差がある

引用

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?