I guess maybe what I should be looking at is how to declare undefined in PHP. I forgot that I usually insert "var undefined;" in my JS template to make this work. I guess I need to do the same in PHP... but declaring variables is a little different.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Well, I'm not looking to define a variable as undefined, I'm trying to set undefined to null by declaring it.
In JavaScript,
Code:
var undefined;
takes a reserved word, undefined, and defines it, so that whenever a variable is undefined and gets called, it will return "undefined" instead of throwing an undefined variable error. This way, you can use the "||" operator instead of using the whole typeof() thing. It's not a strict standards compliant method, but it works and makes for easier error handling. Even jQuery uses it.
Nope, nothing like that in PHP that I've ever seen.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
or "", or "0", or an empty array, or null etc. This technique seems dodgy enough in javascript! Just use isset() to see if a variable has been defined.
or "", or "0", or an empty array, or null etc. This technique seems dodgy enough in javascript! Just use isset() to see if a variable has been defined.
I agree. So, jamesbcox1980, the answer is no. As I said, php always return a Boolean value on Boolean operators.
Bookmarks