0

In a shortcode context, is there any difference here?

array(
        'slideshow' => '',
    ), 

and

array(
        'slideshow' => NULL,
    ), 

Is there a best practice for that?

5
  • Can you explain why you are asking this question? Are you getting errors? "in shortcode context" is not much to go on. Can you post all of the relevant code?
    – s_ha_dum
    Commented Aug 5, 2013 at 3:45
  • No errors. I'm just wondering if there is any technical difference between them.
    – Daniel
    Commented Aug 5, 2013 at 3:47
  • There is a technical difference but whether it will cause trouble is another question. I'd guess "probably not".
    – s_ha_dum
    Commented Aug 5, 2013 at 3:49
  • 1
    Yes, there is a difference. Both will evaluate to false in a boolean context, but NULL is not the same as the empty string. Without knowing what you are doing with the array, it is impossible to tell if your code will react differently with the two different values.
    – Ben Miller
    Commented Aug 5, 2013 at 3:55
  • Sorry if I messed up things here, but I meant to ask just a general question. In my example, I used a slider shortcode. The slideshow parameter will receive a string. I asked the question because I saw some codes where some use "" and others NULL. I just wanted to know if one is better than other.
    – Daniel
    Commented Aug 5, 2013 at 4:00

1 Answer 1

1

If the 'slideshow' key is normally supposed to contain a string value, but you want to give it an empty value, then give it the empty string. The empty string is still a string data type, so it is more likely to react the way you expect in a string function. The null value is not a string, and if you don't have more information on how it is used, may or may not behave the way you want it to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.