I see. Sometimes JavaScript and PHP create a confusion in my head especially in this area when variable is not defined yet.
But you still can have a smaller code by having a simple return instead of IF statement.