Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43920 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99194 invoked from network); 13 May 2009 09:14:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 May 2009 09:14:11 -0000 Authentication-Results: pb1.pair.com header.from=olafurw@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=olafurw@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.166 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: olafurw@gmail.com X-Host-Fingerprint: 209.85.219.166 mail-ew0-f166.google.com Received: from [209.85.219.166] ([209.85.219.166:49584] helo=mail-ew0-f166.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/9C-64369-16F8A0A4 for ; Wed, 13 May 2009 05:14:10 -0400 Received: by ewy10 with SMTP id 10so563014ewy.23 for ; Wed, 13 May 2009 02:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=Iy9eUJFIO4YOVf82O+ccasmB+AAmfuJdhPagkMVeX3Q=; b=jCsvBjVc9qSUnHUe4tT56le8JJ9MMHMWUCI14naoYNU9FyFMsGfnPbpM0Ofv0Eyysc GqWQz5g8H4DmcEpXz2ilf8UG9kYQc0zk+tn1FLZOUfpo7y7gb8qFbILWmQFfTGGjwndf P1Ix6rZMruqU3o3v70Sp6jOKao4EH2F8gyk54= 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 :content-type; b=E5zIJttd1RscSoeTcqNBM4pVSUa3ltqJT7ly0CREXqkOKUeaZ2zb1Q06aYIQmTq27M v3Ssn8DCzu56A4suevmlhfFXB8GA+6FR6BA1dhGpD8H2Q5piT5+oqpCvepun6w3LMjbk 1mgOGw4hgdXhxvdG2L1c2seGkZgyOP8rXdw4g= MIME-Version: 1.0 Received: by 10.216.24.141 with SMTP id x13mr312282wex.106.1242206046711; Wed, 13 May 2009 02:14:06 -0700 (PDT) In-Reply-To: References: <8c35d7690905120935t18722295i69217245c9296a6d@mail.gmail.com> <4A09CE36.5070908@moonspot.net> <8c35d7690905121413ke040115w3080d95a514781c3@mail.gmail.com> Date: Wed, 13 May 2009 09:14:06 +0000 Message-ID: <8c35d7690905130214n47e36d78wd7570ec7b2fb5a50@mail.gmail.com> To: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016e6dbe88926eefc0469c7a207 Subject: Re: [PHP-DEV] The constant use of isset() From: olafurw@gmail.com (=?ISO-8859-1?Q?=D3lafur_Waage?=) --0016e6dbe88926eefc0469c7a207 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 2009/5/12 Ionut Gabriel Stan > 2009/5/13 =D3lafur Waage : > > 2009/5/12 Brian Moon > > > >> $foo =3D filter_input(INPUT_GET, "foo", FILTER_UNSAFE_RAW); > >> > >> That would have a value if set or null if not set. It also allows you > to > >> validate it using filters if you wanted to. This of course only works > with > >> GPC variables, but it is a great solution. > >> > >> Brian. > >> -------- > >> http://brian.moonspot.net/ > > > > > > Can this be turned into a userland function? > > If you're interested in userland code, then you have two solutions: > 1. Make functions like GET, POST, COOKIE, SESSION and use them instead > of the superglobals (functions are superglobal). An example: > ---------------------------------------------------------------- > > // PHP < 5.3 > function GET($key, $default =3D null) { > return isset($_GET[$key]) ? $_GET[$key] : $default; > } > > // PHP >=3D 5.3 > function GET($key, $default =3D null) { > return isset($_GET[$key]) ?: $default; > } > > > 2. Use ArrayObject to override the superglobals in an auto_prepend_file: > ----------------------------------------------------------------- > > $_GET =3D ArrayObject($_GET); > > > > Anyway, these will save the trouble with the superglobals, not with > ordinary arrays. > Yes this will work with GPC variables but not with any other variable. And passing values to it even feels right. if(GET("foo") =3D=3D "bar") > > > > > > Olafur > > > > > >> > >> > >> On 5/12/09 11:35 AM, =D3lafur Waage wrote: > >> > >>> While researching for this suggestion I found this rfc proposal > regarding > >>> ifsetor() ( http://wiki.php.net/rfc/ifsetor?s[]=3Disset > < > >>> http://wiki.php.net/rfc/ifsetor?s%5B%5D=3Disset>) > >>> and it's rejection point was that it was currently not possible ( > >>> http://marc.info/?l=3Dphp-internals&m=3D108931281901389&w=3D2 ) > >>> > >>> But would it be possible to check for a value of a variable if it is > set? > >>> > >>> Since I often do (and see others do) > >>> > >>> if(isset($_GET["foo"])&& $_GET["foo"] =3D=3D "bar") > >>> or even worse > >>> if((isset($_GET["foo"])&& $_GET["foo"] =3D=3D "bar") || > >>> (isset($_GET["baz"])&& > >>> $_GET["baz"] =3D=3D "bat")) > >>> > >>> to be able to do something like this > >>> > >>> if(isset($_GET["foo"]) =3D=3D "bar") > >>> or > >>> if(isset($_GET["foo"]) =3D=3D "bar" || isset($_GET["baz"]) =3D=3D "ba= t") > >>> > >>> That isset (or some other language construct) would return the variab= le > if > >>> it were set and false if it was not. > >>> > >>> Thanks for your time, i know this has probably been talked to death i= n > one > >>> form or other. > >>> > >>> =D3lafur Waage > >>> olafurw@gmail.com > >>> > >>> > > > > > > -- > Ionut G. Stan > I'm under construction | http://igstan.blogspot.com/ > --0016e6dbe88926eefc0469c7a207--