I was wondering if this if statement :
if(session_id()===""){}
is equivalent to this if statement :
if(!session_id()){}
Both works for me!
but I like the sorter line so I was just wondering if it's 100% equivalent and I can rely on that to detect if session is started.
Those statements are not fully equivalent.
if(!session_id()){}
means if(session_id() != TRUE){}
so the session_id()
function could return 0
, FALSE
, ''
, NULL
.
and if(session_id()===""){}
is checking if session_id()
is returning empty STRING, so the only option, for which the if
statement will return TRUE, is ''
.
From PHP Manual about session_id()
:
session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists).
So, the preferable is to use the 1st way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With