Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34954 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52188 invoked by uid 1010); 27 Jan 2008 11:13:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 52173 invoked from network); 27 Jan 2008 11:13:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2008 11:13:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:41102] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/B8-08286-E676C974 for ; Sun, 27 Jan 2008 06:13:52 -0500 Received: from MBOERGER-ZRH.corp.google.com (109-178.78-83.cust.bluewin.ch [83.78.178.109]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 3937D1B3638; Sun, 27 Jan 2008 12:13:47 +0100 (CET) Date: Sun, 27 Jan 2008 12:13:27 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <5310338527.20080127121327@marcus-boerger.de> To: Sam Barrow CC: Sebastian , internals@lists.php.net In-Reply-To: <1201368129.8418.8.camel@sams-room> References: <1201368129.8418.8.camel@sams-room> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] ifsetor like expression in php6 From: helly@php.net (Marcus Boerger) Hello Sam, as others pointed out & results in unwanted entries being present. So the second time you use ifsetor on those entries, you do not get the default back but rather NULL. Actually in your implementation you never get the default back. Please read the archives, all of this has been discussed several times and we have had a bunch of in depth explanations. In fact our archives hold a lot of information valid to people new to the list as well as for us following the list for years. I guess I am not the only one having my own searchable archive always with me - for a reason. marcus Saturday, January 26, 2008, 6:22:09 PM, you 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 >> Best regards, Marcus