Conversation started Jan 5, 2013 at 2:43.
toscho
Jan 5, 2013 02:43
Yoda conditions
these are . —
toscho
3 hours ago
1 hour later…
bungeshea
Jan 5, 2013 04:03
@toscho I was just converting the conditions to Yoda conditions in one of my plugins, and I was
shocked
to learn that in a few cases I had only been using
one
equals sign when comparing!
toscho
Jan 5, 2013 04:27
@bungeshea This cannot happen if you make it a habit to write always three
===
, ie. run a strict comparison.
bungeshea
@toscho Is there ever a situation where you shouldn't run a strict comparison? I wasn't sure if using it all the time would mess up something.
toscho
@bungeshea Yes, look what WordPress does with
pre_get_option_ . $option
. :D
And in one of my plugins I am using
-1
as an ID for a ghost user.
I am relying in weak comparisons in these cases.
bungeshea
@toscho So the 'default' comparison operator I should use is
===
, not
==
?
toscho
yes
bungeshea
Okay, thanks
:)
toscho
Jan 5, 2013 04:42
But
$_REQUEST
values are either array or string, never integer, even if you
want
an integer.
bungeshea
That's what
intval()
is for
Conversation ended Jan 5, 2013 at 4:44.
View all rooms
Yoda conditions
Jan '13
5
The Loop
Where humor doesn’t work.
context of the conversation
join this room
about this room
Participants
toscho
53%
bungeshea
46%
all times are UTC
site design / logo © 2025 Stack Exchange Inc;
legal
mobile