I think the explanation is a bit short, and that beginners could easily make mistakes.
strlen andisset do not have the same functionality:
strlen allows to test the length of a string.
isset allows you to test that variable is defined and notnull.
You really need to have a specific performance need to use what is described in the article (ie iterate 1,000,000 times).
In most cases, I prefer to use strlen: if your business need is for example that your password has a minimum length of 8 characters, then the translation in the code will be much more explicit than withisset
if(strlen($password)<8){// error}
if(!isset($password[7])){// what does this "7" mean, the business need asks 8// error}
If you want to test that a string is not empty, it is better I think to do
I think the explanation is a bit short, and that beginners could easily make mistakes.
strlen
andisset
do not have the same functionality:strlen
allows to test the length of a string.isset
allows you to test that variable is defined and notnull
.You really need to have a specific performance need to use what is described in the article (ie iterate 1,000,000 times).
In most cases, I prefer to use
strlen
: if your business need is for example that your password has a minimum length of 8 characters, then the translation in the code will be much more explicit than withisset
If you want to test that a string is not empty, it is better I think to do
rather than
Thanks @Jimmy Klein
awesome
Thanks @Jimmy Klein very much