Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104343 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81222 invoked from network); 11 Feb 2019 19:16:57 -0000 Received: from unknown (HELO mail-lj1-f177.google.com) (209.85.208.177) by pb1.pair.com with SMTP; 11 Feb 2019 19:16:57 -0000 Received: by mail-lj1-f177.google.com with SMTP id s5-v6so9167598ljd.12 for ; Mon, 11 Feb 2019 07:59:36 -0800 (PST) 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=MoVm2PnWNWiKZuag3frfgjPZCCTXCKJOAM6mz+tNAqo=; b=sl/R90PC+QobisdiyWewp8D0nlfgejViI9a6cecJCyi9xT4GgtuIxYUBdWjhI7kvjq GeXS+EO3z6zPHQZifVid9TwBVD8R8hT/tSk8dwbAVWVIAvrAJy2Vg91HG1xBA6/4tVYG pKjUsr8gOx69Hu9tTG4UG5ohYByu2CWrwn/uQBVuNNzGN98XVrQryScvpu6azMJc+1eJ cWw9p9FXFF+ZAQVfdzKHx6pEIZpHp9QpBul4y9RLVA+Tg2BafXaCg149Q/58Ji/dqFBw fChzUYXlIlKfJyrSYvJvYQ74JscGwt8Zqkc0sCS1lNKLUI6mT+VVWaJj907OdIoIIq2X AlZA== X-Gm-Message-State: AHQUAuYD8sP5hPydvaUxsR4Zz7c4qdkFZ+YAQZl2D90lBTItLZJRhVGo 5Bkja/iLso5dVfxVMhJd8o+EvpGgIWxz1cr3QlQ= X-Google-Smtp-Source: AHgI3IZJ2HeuYNJlaavYXoUyttDPSMnT8EK8fNnkKFwoPFIH5tLuIcyJKLEBW7A2to5CZAiMGGEJcuiaIFZ8fGkFyw8= X-Received: by 2002:a2e:868c:: with SMTP id l12-v6mr22174151lji.90.1549900775630; Mon, 11 Feb 2019 07:59:35 -0800 (PST) MIME-Version: 1.0 References: <5437a651-8263-49e9-b87e-d8d052d66c99@web.de> In-Reply-To: <5437a651-8263-49e9-b87e-d8d052d66c99@web.de> Date: Mon, 11 Feb 2019 08:59:17 -0700 Message-ID: To: "Woortmann, Enno" Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Variadic is_*() functions From: levim@php.net (Levi Morrison) 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.