stijn0713 Posted March 29, 2012 Share Posted March 29, 2012 probably a very stupid question, but i pose it because it's counterintuitive for me to write it: i find in alot of wordpress code if statements like: if ( false === $var) i suppose it's the same as if ( $var === false) ? why would one right it in the first way? Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/ Share on other sites More sharing options...
trq Posted March 29, 2012 Share Posted March 29, 2012 Those two expressions are equal, some people find it easier to read one way or the other. Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/#findComment-1332336 Share on other sites More sharing options...
stijn0713 Posted March 29, 2012 Author Share Posted March 29, 2012 thanks! if i may ask another question: function current_time( $type, $gmt = 0 ) {} What's the point of writing $gmt = 0 as a parameter of this function? I suppose it doesn't mean it always overwrites to 0 your second parameter passed Does it mean that you don't always need to pass gtm as a parameter to the function and in case left out, it's set 0 by the function? thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/#findComment-1332347 Share on other sites More sharing options...
smerny Posted March 29, 2012 Share Posted March 29, 2012 Does it mean that you don't always need to pass gtm as a parameter to the function and in case left out, it's set 0 by the function? yes Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/#findComment-1332349 Share on other sites More sharing options...
Muddy_Funster Posted March 29, 2012 Share Posted March 29, 2012 it meens that 0 is the default value of $gmt. so if nothing is passed in for that when the function is called it will have a value. it saves enforcing a refference for a fairly static value and at the same time makes the function more robust as it won't fail with an "undefined variable" warning if no value is passed in. So for this example when the function is called $type MUST be some value at runtime, but $gmt will default to 0 if value is passed in for it. Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/#findComment-1332351 Share on other sites More sharing options...
stijn0713 Posted March 29, 2012 Author Share Posted March 29, 2012 ok, thanks for the replies! Quote Link to comment https://forums.phpfreaks.com/topic/259944-basic-question-if-statement/#findComment-1332353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.