Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34943 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4250 invoked by uid 1010); 26 Jan 2008 18:18:56 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4235 invoked from network); 26 Jan 2008 18:18:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2008 18:18:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 66.249.82.224 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 66.249.82.224 wx-out-0506.google.com Received: from [66.249.82.224] ([66.249.82.224:6011] helo=wx-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/11-08850-E897B974 for ; Sat, 26 Jan 2008 13:18:55 -0500 Received: by wx-out-0506.google.com with SMTP id s14so1043452wxc.26 for ; Sat, 26 Jan 2008 10:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=I0pSOSWPo9xmZpQTw+oy5gYRTnLr1RuOEiUK+u+eFiM=; b=iew6dWYYlnNHJcloJOgz8iIvhtw57TfuhIGqyelzA6ytUHaKfrenKhkvn0QcPeT+p0k8Yex0Za5YPPofMdJdFivDM256tqn2VtXcgqiuoQEod4JJBNNjfcAAM01azZ1LUh3r602y7Wzn7dCjQHnntYXxnzREOTOZh2U0mm7up38= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=iW7kCoFCErSJJcnQ/+sivizpHKXGj+n0CzJXIUdXfeuYV9wvdrrKCo5r4PU4aaQdV5avKtvbZjY6RsDM38dD8Azgyz6qw6X8G7YiyAeHeerU7Uwn9sxSOInl6l7RRg4nDuRfIwXCsZSNkPA7iBztT5mZ6ihkRe8kKAwPzVM4PG0= Received: by 10.70.115.17 with SMTP id n17mr2268612wxc.17.1201371531947; Sat, 26 Jan 2008 10:18:51 -0800 (PST) Received: by 10.70.30.3 with HTTP; Sat, 26 Jan 2008 10:18:51 -0800 (PST) Message-ID: Date: Sat, 26 Jan 2008 19:18:51 +0100 Sender: ekneuss@gmail.com To: "Sam Barrow" Cc: internals@lists.php.net In-Reply-To: <1201368129.8418.8.camel@sams-room> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <1201368129.8418.8.camel@sams-room> X-Google-Sender-Auth: 3044df26045974f2 Subject: Re: [PHP-DEV] ifsetor like expression in php6 From: colder@php.net ("Etienne Kneuss") Hi, usage of references here have some bad consequences, it will pollute the input array with null entries: function foo(&$a) { } var_dump(array_key_exists('inexistent', $_GET)); // bool(false) foo($_GET['inexistent']); var_dump(array_key_exists('inexistent', $_GET)); // bool(true) will actually create the inexistent entry and fill it with null. Again, there is no perfect implementation of an issetor in userland. On Jan 26, 2008 6:22 PM, Sam Barrow wrote: > I'm sorry I misunderstood. If specifying like "$var ?: 5" then it should > throw an E_NOTICE, as this is a conditional that checks the value of a > variable ($var). > > Sebastian, for assigning of a default value is a variable is not set, I > would recommend using something like this (this is what I use): > > function ifsetor(&$var, $or) { > return isset($var) ? $var : $or ; > } > > Because $var is passed by reference, it won't throw an E_NOTICE when > passing an undeclared variable. > > On Sat, 2008-01-26 at 17:30 +0100, Sebastian wrote: > > > hi, > > > > i just found the new ifsetor like construction in php6. It left me the > > question why php has to throw an E_NOTICE when the variable is not set. This > > is basicly because that actually is the meaning of this construction, > > checking if the variable is set and if it isnt give back a standard value. > > Of course i know this construction can be (mis)used with an Boolean check > > ($var===$var2), but this does not make much sence either because TRUE will > > then be assigned to the new variable if the expression evaluates to TRUE > > (but please correct me if theres a real use for this). > > > > So in any case it would be better to remove the Boolean check feature and > > make it a simple ifsetor() without the E_NOTICE again. > > > > For those of you who have not heard of it heres an example: > > > > > > > // If $_GET['foo'] is set, then its value will be assigned to $foo, > > // otherwise 42 will be assigned to $foo. > > > > $foo = $_GET['foo'] ?: 42; > > > > ?> > > > > Greetings > > > > Sebastian > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- Etienne Kneuss http://www.colder.ch Men never do evil so completely and cheerfully as when they do it from a religious conviction. -- Pascal