Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34941 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74892 invoked by uid 1010); 26 Jan 2008 17:22:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 74877 invoked from network); 26 Jan 2008 17:22:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jan 2008 17:22:06 -0000 Authentication-Results: pb1.pair.com header.from=sam@sambarrow.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sam@sambarrow.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sambarrow.com from 205.234.132.11 cause and error) X-PHP-List-Original-Sender: sam@sambarrow.com X-Host-Fingerprint: 205.234.132.11 scottsdale.servershost.net Received: from [205.234.132.11] ([205.234.132.11:34175] helo=scottsdale.servershost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/3F-08850-E3C6B974 for ; Sat, 26 Jan 2008 12:22:06 -0500 Received: from 208-58-196-175.c3-0.slvr-ubr1.lnh-slvr.md.cable.rcn.com ([208.58.196.175]:50356 helo=[192.168.1.88]) by scottsdale.servershost.net with esmtpsa (SSLv3:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1JIojE-0004jN-Ma; Sat, 26 Jan 2008 11:22:04 -0600 To: Sebastian Cc: internals@lists.php.net In-Reply-To: References: Content-Type: text/plain Date: Sat, 26 Jan 2008 12:22:09 -0500 Message-ID: <1201368129.8418.8.camel@sams-room> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 Content-Transfer-Encoding: 7bit X-Antivirus-Scanner: Clean mail though you should still use an Antivirus X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - scottsdale.servershost.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - sambarrow.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] ifsetor like expression in php6 From: sam@sambarrow.com (Sam Barrow) 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 >