Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51956 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14860 invoked from network); 20 Apr 2011 15:20:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2011 15:20:00 -0000 Authentication-Results: pb1.pair.com header.from=markg85@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=markg85@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: markg85@gmail.com X-Host-Fingerprint: 209.85.216.170 mail-qy0-f170.google.com Received: from [209.85.216.170] ([209.85.216.170:42939] helo=mail-qy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4E/84-24878-F99FEAD4 for ; Wed, 20 Apr 2011 11:19:59 -0400 Received: by qyk32 with SMTP id 32so2416985qyk.8 for ; Wed, 20 Apr 2011 08:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=HlwWiZs2Q/6q44K70QozUqD4XxnPEL3pxn1g+s29BuU=; b=tN9Gmkb7PccEFFV8tWUDXx8OEijqCM9lW7mkM+9j3xUMFKr2GAvtBlJ8nTpwtmbxYS P2DyxlWPrim9PJwbLk9jyc/HFGo9l3+0sR7gjUco+n0vojJZ5KzPtroonj6LV2hGz9mP CfuWBOL8YmuOLBhLRmZC60b9T0ompodvtNpeo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=PiCKHulngSu/Om6APze9EST5qukdrYCnfYXwTsCGh5WIrEgAG/x4as9gnM5NJu1jRH yCum6I1rydtbruDephgJ3rqBF+yNSR/HgCB2PtTI8vJ06oyakiurpACCWPfd5SO9/etW i6QeINheuKMlvp9Wpp0K/GdvSwP7wN9QwZxSY= Received: by 10.229.22.138 with SMTP id n10mr5484597qcb.175.1303312796841; Wed, 20 Apr 2011 08:19:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.185.200 with HTTP; Wed, 20 Apr 2011 08:19:36 -0700 (PDT) In-Reply-To: <20110420151205.GI32571@phcomp.co.uk> References: <20110420151205.GI32571@phcomp.co.uk> Date: Wed, 20 Apr 2011 17:19:36 +0200 Message-ID: To: Mark , internals@lists.php.net Content-Type: multipart/alternative; boundary=0016364eec7e497ba504a15b2810 Subject: Re: [PHP-DEV] Function proposal: varset From: markg85@gmail.com (Mark) --0016364eec7e497ba504a15b2810 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Apr 20, 2011 at 5:12 PM, Alain Williams wrote: > On Wed, Apr 20, 2011 at 04:55:00PM +0200, Mark wrote: > > Hi, > > > > This proposal is for the often called line like this: > > $var = isset($_GET['var']) ? $_GET['var'] : ''; > > > > Only a shorter and imho a cleaner solution to get the same: > > $var = varset($_GET['var']); > > It should be called var_set() - better on name space pollution. > oke > > However there is a slight issue with this approach. If notices are > turned on > > this code will generate a notice while i think it should not do that. But > > perhaps this approach is "to short". > > A slightly different implementation (and longer) prevents the notice: > > If is is a language element (like isset()) then you can avoid this problem. > Could you explain that a bit more? > I do find a lot of code, in simple scripts, that does just that. > > It might be nice to extend it such that if the 1st argument is a list then > the > first in the list which is set is returned, eg: > > $var = var_set(($_GET['var'], $_POST['var']), 'default'); > > I might be missing the point here, but the way i understand it that can give unexpected results.. since it returns the first element from an array in your suggestion but that's not what you want to do. > -- > Alain Williams > Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT > Lecturer. > +44 (0) 787 668 0256 http://www.phcomp.co.uk/ > Parliament Hill Computers Ltd. Registration Information: > http://www.phcomp.co.uk/contact.php > #include > --0016364eec7e497ba504a15b2810--