Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

php - What is a reason of placing boolean or null before comparison operator?

In PHP, what is an underlying reason of placing either boolean or null before identical comparison operator?

false === $value;   
null === $value;

It seems to me that it is same as saying

$value === false;

Is it just a personal preference or there is a concrete reason why people do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's a convention to avoid the mistake of accidentally assigning a variable.

$value = false;

instead of

$value === false;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...