Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69198 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99727 invoked from network); 18 Sep 2013 14:48:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Sep 2013 14:48:55 -0000 Authentication-Results: pb1.pair.com header.from=patrick.allaert@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.49 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 74.125.83.49 mail-ee0-f49.google.com Received: from [74.125.83.49] ([74.125.83.49:32974] helo=mail-ee0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/5C-43258-55DB9325 for ; Wed, 18 Sep 2013 10:48:54 -0400 Received: by mail-ee0-f49.google.com with SMTP id d41so3440704eek.8 for ; Wed, 18 Sep 2013 07:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=80wGKY/9CtleH3n0+yc4q5THAXkNxq5WIftPJu+DYnw=; b=Te6yMG1/JTPWBUMEB07UGEmbt/uJLPfUpkQaqyy9YfmohX7aGrUKW63YjIaXh7kh8N qtLfDBzif3D8upPbec2jaJ/ONFF4pSfZq6ogpQKrRQ0U3xRWdWZfGXpVb/RQZ2/GwVNV cFf0DHBdydSHWlzsLscW3BYB7f1zh2pudXMmX2MHscyVyxZkLWMwGzj23uIOBAUQRGDs JGN6v/07y7Jsr2Fa+wa61VfAZJxCpTxK66dibO3BjT+au/sgZKdfUSlRyDxv5EoRQt54 54rmfYUcwnut6uJWwdOap07RCBKQyb67AsEgYJRSNqDNGmzfFI66laRbVAH/rfB23BcL k8Dw== MIME-Version: 1.0 X-Received: by 10.14.88.65 with SMTP id z41mr29321063eee.38.1379515730072; Wed, 18 Sep 2013 07:48:50 -0700 (PDT) Sender: patrick.allaert@gmail.com Received: by 10.14.144.66 with HTTP; Wed, 18 Sep 2013 07:48:49 -0700 (PDT) In-Reply-To: <012B9378-3C3A-4169-96D3-3B57D6C7A82C@seancoates.com> References: <49D57F66323040FC9AE48244DAAF3771@gmail.com> <012B9378-3C3A-4169-96D3-3B57D6C7A82C@seancoates.com> Date: Wed, 18 Sep 2013 16:48:49 +0200 X-Google-Sender-Auth: ZhBDFZjWt08JplpgjvmudllkJFk Message-ID: To: Sean Coates Cc: Leigh , PHP Development Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Re: Allowing is_* functions to accept multiple parameters From: patrickallaert@php.net (Patrick ALLAERT) 2013/9/18 Sean Coates : >> i.e. is_null($a, $b, $c) would be the same as is_null($a) && is_null($b) >> && is_null($c) > > Note that this would not be semantically equivalent in this form, even if `is_null()` did accept multiple parameters, because of the short-circuiting with `&&`: > > > function are_null() { > foreach (func_get_args() as $a) { > if ($a !== null) { > return false; > } > } > return true; > } > > function destroy_data() { echo "DESTROYING DATA\n"; } > > // old form: short-circuited; data is not destroyed > if (is_null(null) && is_null(false) && is_null(destroy_data())) { > echo "All null.\n"; > } else { > echo "Not null.\n"; > } > > echo "----\n"; > > // proposed form: no short-circuit; parameters are evaluated at call time and data is destroyed > if (are_null(null, false, destroy_data())) { > echo "Still null.\n"; > } else { > echo "Still not null.\n"; > } > Not a good idea IMHO: it would complexify the execution a lot, think about: $test = "are_null"; if ($test(null, false, destroy_data())) { echo "Still null.\n"; } else { echo "Still not null.\n"; } Looking at the AST wouldn't be enough to tell what would or wouldn't be short-circuited. It looks fine to have is_* functions working on multiple values as Leigh originally proposed. I also feel that it would mostly be used/useful on variables. People worrying about performance and/or execution of code with short-circuiting can (and should) still rely on "&&".