PHP is an interpreted language while Crystal is a compiled one.
AFAIK There is no way to check at runtime an undefined variable, simply because an attempt to use an undefined variable will produce an error during compilation:
Error in 9.cr:1: undefined local variable or method 'foo'
puts foo
^~~
This applies to branches, methods, anything that is invoked but is not defined.
You can only perform comparison against the value of variables and act based on that (ie. variable can be a number or nil)
In that case, you can use if to scope out other possible outcomes.
This behavior is documented in Crystal book:
https://crystal-lang.org/docs/syntax_and_semantics/if_var.htmlHope that helps.
--
Luis Lavena