Home  >  Q&A  >  body text

The difference between return '' and return in PHP

I tried it, and the results returned by var_dump were all NUll. Baidu also found no clear answer.
I saw that return '' seems to be used more often in the code written by others. Could you please tell me about return '' and return in PHP. What's the difference?

为情所困为情所困2719 days ago749

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-31 10:36:30

    • return '' returns an empty string

    • return returns null
      You can see it through the var_dump result.

    For PHP's weakly typed language, there is actually no difference if you don't use it carefully.
    But using ===, the comparison will show false

    reply
    0
  • 迷茫

    迷茫2017-05-31 10:36:30

    I think generally don’t return null, return an empty string or empty array, so that the data acquisition party can process it uniformly (less judgment (~—~))

    reply
    0
  • Cancelreply