Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between $str == '' and strlen($str) == 0 in PHP?

Tags:

php

strlen

As the title says: Is there a difference between $str == '' and strlen($str) == 0 in PHP? Is there any real speed difference and is one better to use than the other?

like image 714
Darryl Hein Avatar asked Dec 19 '08 19:12

Darryl Hein


1 Answers

i find it clearer to just do "if (!$str)" .. not sure about '==' but '!' should be able to yeld better optimization techniques, as no typecasting is ever done, and is safe for strings, arrays, bools, numbers...

like image 149
Quamis Avatar answered Oct 08 '22 00:10

Quamis