Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:48744 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7229 invoked from network); 11 Jun 2010 18:04:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jun 2010 18:04:07 -0000 Authentication-Results: pb1.pair.com header.from=hannes.magnusson@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=hannes.magnusson@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: hannes.magnusson@gmail.com X-Host-Fingerprint: 209.85.161.42 mail-fx0-f42.google.com Received: from [209.85.161.42] ([209.85.161.42:39101] helo=mail-fx0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/90-08093-69A721C4 for ; Fri, 11 Jun 2010 14:04:07 -0400 Received: by fxm5 with SMTP id 5so1052824fxm.29 for ; Fri, 11 Jun 2010 11:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=1wwvvSqGuw3D7Ej+9NLZjhHJyKg3o/iHw3WC8oK/GPw=; b=CYIDmsruJFG8mJlpKBnatK8k7VWDKMIw7YLYJDX5HKy5t4DNA6q7KlAh6MIT2KwcE9 waKHWGrtZuOy+buTcukf/8OdRzG5eNcM7KRXSjo991/7GVfG0hg65UKymgymFMtOlWcC KA3Ra5E5IAy/gG0L/go5FtNIgnqbk73itoMHY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=eI3euoHlclv1OZMzZ23/vkGwINbCpnLeeF7G5JFT8OdafYyOZTt1n3yrBbSnl4N03d I5ipNh3/JpeHVAvx3mw6TyaLhHHR21B+JI1TX11Grq/TeiWVES+DvAutKjI3Efie3jQM 5y00FQfinJo2tl/nyZLz19MViAbWOdLQXqyog= MIME-Version: 1.0 Received: by 10.216.93.81 with SMTP id k59mr1282783wef.92.1276279443728; Fri, 11 Jun 2010 11:04:03 -0700 (PDT) Received: by 10.216.229.33 with HTTP; Fri, 11 Jun 2010 11:04:03 -0700 (PDT) In-Reply-To: <4C1275AB.8000201@moonspot.net> References: <4C1275AB.8000201@moonspot.net> Date: Fri, 11 Jun 2010 20:04:03 +0200 Message-ID: To: Brian Moon Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Detecting if a null variable exists? From: hannes.magnusson@gmail.com (Hannes Magnusson) On Fri, Jun 11, 2010 at 19:43, Brian Moon wrote: > Is it just me or are we missing a way in the language to check if a variable > that has been set to NULL exists or not? > > is_null() on an unset variable throws a NOTICE. > $var === null throws a notice. > > So, you have to use isset()? But, ah, > > $var = null; > if(isset($var)) > > yields false. > > Is array_key_exists("var", $GLOBALS) the only solution to this problem? This question creeps up every once in a while, and I have seen bunchload of code that uses array_key_exists("foo", $array); rather then isset($array["foo"]) because of it. I however have never seen a proper usecase.. I tend to "initialize" my variables, and array keys, as null, so I never have to do these kind of checks. And if you don't initialize your variables, then you can turn of E_NOTICE if it bothers you. -Hannes