Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51877 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52624 invoked from network); 12 Apr 2011 11:33:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Apr 2011 11:33:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.177 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qy0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:52602] helo=mail-qy0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/60-50366-49834AD4 for ; Tue, 12 Apr 2011 07:33:41 -0400 Received: by qyl38 with SMTP id 38so4489156qyl.8 for ; Tue, 12 Apr 2011 04:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc:content-type; bh=F6bg9r5DQP/2alIBhvjUbmuYKiiDsFS5Q2IkwUn6kMo=; b=dOnO9XVq/z3YgPrIe0pWnT6KQjyL+i4HPdsYRJJUD5AVa+T7p/EPo1W9nfnxuZefAy dIONzOMXBFbvCO7+RVWT1CulXAx8c5t19BojL/0S6FnMeT7zF/jTk4dCcNtiDpBOr8ZN ZC+4vtQ/pPZKnW/23mCb+xHV4pnHUAeMyEQMU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; b=TkitiCMRvp4weD7G5f66nN602cn/GZIU28+Heg/F6uaS5PBK4KeI4dvFRxmAqJNxqC sqVHblmu1UI04cncErTAW2yWr+Ns9YUkv2CNNflxGTatHHSEyO3b26im8SwoQo3UrCdq JtMyqIR1IqYuELXWKZWIUtfJq7xjAYgeuDGjs= Received: by 10.229.46.74 with SMTP id i10mr5171732qcf.64.1302608017113; Tue, 12 Apr 2011 04:33:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.106.194 with HTTP; Tue, 12 Apr 2011 04:33:17 -0700 (PDT) Reply-To: RQuadling@googlemail.com In-Reply-To: <4DA26602.6080303@lorenso.com> References: <4DA26602.6080303@lorenso.com> Date: Tue, 12 Apr 2011 12:33:17 +0100 Message-ID: To: dante@lorenso.com Cc: Internals Mailing List Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] proposed access modifier "silent" ... was: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: rquadling@gmail.com (Richard Quadling) Considering that the main impetus for these threads is to write code that does not generate the notice regarding missing variables or indices, neither isset() or empty() will provide that completely. If a variable is declared, but assigned null, it is not set and it is empty. But so what. The variable exists and will not generate a notice if access is attempted. No suppression of the non existent notice is necessary. The issue is one of undefined variables and indices. That's what the E_NOTICE says ... Notice: Undefined variable Notice: Undefined index To directly detect the presence of a key, then array_key_exists() is the function that covers the requirement. Global variables are easily detectable using array_key_exists($key, $GLOBALS); Properties for an object ... property_exists(). For locally scoped variables, the function get_defined_vars() can be combined with array_key_exists(). But the obvious overhead of having to extract all the variables into a temp array is probably going to be a performance no-no. The script below (and in [1] in case the formatting all goes wonky), demonstrates this. Ideally, a construct that specifically detects if a variable is declared, irrespective of its value, would be the perfect solution as this could be combined with isset() or empty() as the developer needs. Richard. [1] http://pastebin.com/qLNYtfAw '', 'defined_key_null_value' => null, 'defined_key_value' => 'non null element', ); $defined_vars = get_defined_vars(); echo report('Undefined variable ', isset($undefined_variable), empty($undefined_variable), array_key_exists('undefined_variable', $defined_vars)), report('Defined variable null value ', isset($defined_variable_null_value), empty($defined_variable_null_value), array_key_exists('defined_variable_null_value', $defined_vars)), report('Defined variable non-null value ', isset($defined_variable_value), empty($defined_variable_value), array_key_exists('defined_variable_value', $defined_vars)), report('Undefined key ', isset($array['undefined_key']), empty($array['undefined_key']), array_key_exists('undefined_key', $array)), report('Undefined key null value ', isset($array['defined_key_null_value']), empty($array['defined_key_null_value']), array_key_exists('defined_key_null_value', $array)), report('Undefined key non-null value ', isset($array['defined_key_value']), empty($array['defined_key_value']), array_key_exists('defined_key_value', $array)); } tester(); ?> -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY