Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:23102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75446 invoked by uid 1010); 3 May 2006 06:05:49 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 75430 invoked from network); 3 May 2006 06:05:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 May 2006 06:05:48 -0000 X-PHP-List-Original-Sender: dante@vocalspace.com X-Host-Fingerprint: 69.56.193.72 fox02.stravio.com Linux 2.5 (sometimes 2.4) (4) Received: from ([69.56.193.72:43329] helo=fox02.stravio.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 6E/7E-31513-C3848544 for ; Wed, 03 May 2006 02:05:48 -0400 Received: from [127.0.0.1] (c-67-177-79-15.hsd1.tx.comcast.net [67.177.79.15]) by fox02.stravio.com (Postfix) with ESMTP id 2E4F726C306; Wed, 3 May 2006 01:05:45 -0500 (CDT) Message-ID: <44584835.1030807@vocalspace.com> Date: Wed, 03 May 2006 01:05:41 -0500 User-Agent: Thunderbird 1.5.0.2 (Windows/20060308) MIME-Version: 1.0 To: dante@lorenso.com Cc: internals@lists.php.net References: <44584619.60400@lorenso.com> In-Reply-To: <44584619.60400@lorenso.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Seeking 'coalesce' php internal function From: dante@vocalspace.com ("D. Dante Lorenso") D. Dante Lorenso wrote: > I don't think something like this can NOT be written in userspace > because the 'isset' and 'empty' checks need to be run before arguments > can be passed to a user function or warnings will start flying. A > function like this simplifies code which used to look like this: > > if (!empty($_POST["postkey"])) { > $value = $_POST["postkey"]; > } > elseif (!empty($_GET["getkey"])) { > $value = $_POST["getkey"]; > } > elseif (!empty($default_value)) { > $value = $default_value; > } > else { > $value = "hard coded value"; > } > > Into this: > > $value = coalesce($_POST["postkey"], $_GET["getkey"], > $default_value, "hard coded value"); I mean "I DON'T think like this CAN be written in userspace". And, yes, there is a bug in that code up above (around $_GET testing), but the 'coalesce' function removes the test/set with identical values so removes those kinds of careless bugs. Dante