Check if a variable exists

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Aug 18 12:14:34 PDT 2006


Peter Thomassen wrote:
> Hi.
> 
> Is it possible to check if a variable exists, like PHP's isset()?
> 
> Thanks!
> Peter

Typically, you only ever have to ask when doing fairly complex template 
stuff; this is largely the point of a statically-typed language. Mind if 
I ask why you need to check for this? The answer, though, is this:

static if (is(typeof(my_variable))) {
     // ...
}

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org



More information about the Digitalmars-d-learn mailing list