Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104344 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85788 invoked from network); 11 Feb 2019 19:30:53 -0000 Received: from unknown (HELO mail-pg1-f196.google.com) (209.85.215.196) by pb1.pair.com with SMTP; 11 Feb 2019 19:30:53 -0000 Received: by mail-pg1-f196.google.com with SMTP id q206so1484168pgq.4 for ; Mon, 11 Feb 2019 08:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A2aTFAR6Ufy1OmRVGwaXLfOmXg2J1d303B6cQ/K1XC4=; b=Wdizxf8SRUM9JmCtJKlvrbP9QSpc+WcPVCDlLMoLwihvM4fGKLNi0mfDnGKvw3eH40 7U5MQ+eejy6HQ+JM5iGPGITKPaegEwq8U7mfnONZufA6hho0aPSd8EkYalyS/v7Mph8v 4l76GaUuEdUdRfI7E49Tj4i9aYiBVW3ZrjC3pjqpRu6Tjotwj2qa/sB6CUDqCPVKzIHR pVoqVFxXEH66mdtw3CaHnYp4XPMY/EokJ4PY+QKSO7gS9HXj+z4S4Z0lf8NntzSQ04Qa MC+Fw8nrpDF8kgiGWQz7t0vtI2SGOo4mRSHu/o7+9Q+W5XlHe8x6fg/jpfpLb0REgbOG vLGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A2aTFAR6Ufy1OmRVGwaXLfOmXg2J1d303B6cQ/K1XC4=; b=IEzoBxAeyYktIsoarX0IKOzPoeRwM1JTBo66i4FdRdGRQvFyTopsvcRU9I3gfcoZFb yF6c2ms/5EOa+Hg8wM28z1z+33fCIxugHYzc5496L2yhoNfOkI1FejdyxhZp7eFHZ9mR cpKjaoRQUHrRMt9YK05DC0y76J64eED+rg2m9NVwxTTf49nfw+OXuBi4Lh9g9Y+LCdM2 73incKaNtXKkXiN6kcMVHFbqkD5L5awVLN3Na3AkGZ7/KcbGi1QtgQnw44x5QFqLFIvP Vs773AKpKWuNy1PLrrr4N+k18Kyfp9aF1Ui+JW+lnl67pufGCCqdZdrHBiFMGcUqJeFt wYrg== X-Gm-Message-State: AHQUAuaD0lj0VBRPjHeSKb1K9qPZikW5F0rZU3xtcl6qiVcnRA2FOjOH 6PiEHslHHUXD1M1lZ4knLwvUJBwSV7Q7BAc5g94= X-Google-Smtp-Source: AHgI3IZReWpqA05dWKLb4vq0ohFTxm1Bd+mTqFjxvdGhalsNfjBYffmnBQxM8UrnmH35AS9ZAjLJONKKrZI4c7BMsjU= X-Received: by 2002:a62:1049:: with SMTP id y70mr11082890pfi.220.1549901612428; Mon, 11 Feb 2019 08:13:32 -0800 (PST) MIME-Version: 1.0 References: <5437a651-8263-49e9-b87e-d8d052d66c99@web.de> In-Reply-To: Date: Mon, 11 Feb 2019 11:13:20 -0500 Message-ID: To: Levi Morrison Cc: "Woortmann, Enno" , internals Content-Type: multipart/alternative; boundary="0000000000000bb1580581a0971b" Subject: Re: [PHP-DEV] Variadic is_*() functions From: chasepeeler@gmail.com (Chase Peeler) --0000000000000bb1580581a0971b Content-Type: text/plain; charset="UTF-8" On Mon, Feb 11, 2019 at 10:59 AM Levi Morrison wrote: > On Mon, Feb 11, 2019 at 8:39 AM Woortmann, Enno > wrote: > > > > Hi internals, > > > > as I reviewed a bunch of code for handling data from different sources > > (eg. json) in the last days I stumbled over code like this multiple > times: > > > > > > if (!(is_numeric($input['example1']) && is_numeric($input['example2']))) > { > > > > > > if (!is_numeric($input['example1'] || !is_numeric($input['example2'])) { > > > > > > and I had multiple problems with this. > > > > * it's kinda hard to read > > > > * multiple writings for the same logic > > > > * ends up in complex conditionals > > > > > > I searched for discussions regarding this topic and found it was > > mentioned in a 'side thread' of the RFC for changing empty() to a > > variadic a few years ago (https://externals.io/message/82549#82641) and > > I'd like to collect some feedback if it's wothy to revisit the topic to > > write the above example as: > > > > > > if (!is_numeric($input['example1'], $input['example2'])) { > > > > > > Except the is_callable() method all is_*() methods could be extended > > with a variadic behaviour which would check the given values from the > > left to the right and abort if a value doesn't match the condition (in > > the example if a given value is not numeric). So all in all there are > > some points to talk about: Revisit the discussion? Which functions are > > reasonable to be extended? If all functions are reasonable: what to do > > with is_callable()? > > > > regards, > > Enno > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > My position is the same: pushing the variadic behavior into the > functions means that each function needs to pick `||` or `&&` > behavior, both of which are useful. I would rather see more > descriptive function names, such as `all_of` or `any_of`: > > if (!all_of('is_numeric', [$input['example1'], > $input['example2']])) {/*...*/} > > These do not need to be part of PHP core, but perhaps they could be. > > I recognize that there is one downside, which is that lazy evaluation > is lost, but generally don't see it to be an issue in these specific > cases. > > Lazy evaluation doesn't have to be lost if the all_of and any_of functions are written correctly. all_of will return false as soon as one of them fails, and any_of will return true as soon as one of them passes. -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Chase chasepeeler@gmail.com --0000000000000bb1580581a0971b--