Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104347 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98671 invoked from network); 11 Feb 2019 20:13:33 -0000 Received: from unknown (HELO mail-lf1-f53.google.com) (209.85.167.53) by pb1.pair.com with SMTP; 11 Feb 2019 20:13:33 -0000 Received: by mail-lf1-f53.google.com with SMTP id q11so8329917lfd.3 for ; Mon, 11 Feb 2019 08:56:13 -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=lMMhGNRKO4V7QTiqNmSRGDNd87uZgRsEo1X8nmZnF3Y=; b=Uqg+7PLQLQQc465ghy+L+jxwEntgUKZcg/3l0e4BX2Z2os36agpj4gn3DbMsg7NFQL 5xIJ8/WtD9WBCUrhBxy4HOQp5cH85HUWLXXLWX+9XiujQ1iic3IVqMsLCdUt4rPPpTFZ ktyYxVKPJwExNh/8HnM3Fma2mvEtutH8NnQB3CRgD1PEJMNZIAfdDU+vzEgBdSXYOJAU cwGdKPTWPK9kOwQ2kCIKaHzbhmQ4NvSMjK2VUz3rk3W93WFY+/c9wJ4nrA03j85Y2hO0 OC4i9bcAbKzOzfiuXqGQzFqeymFnBB1Z7tIAP1M7Y5oEhZkFnXX3qxTn6HZ/JneW4MCx FWMw== 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=lMMhGNRKO4V7QTiqNmSRGDNd87uZgRsEo1X8nmZnF3Y=; b=hUUgCgNp+M/n/7hCYJiI0cj6lR9VY3/rzz8OADP2v6R7aNViX0Blf44TcLZSzSrycS j49uLgXa+gn78/09ITvdQEPsh3fodR9Ep98oYCZHIJc7PlszZ/UQd2VjWVTW+mDvslxk XFVIapl9hvWOViEJ9ymfRJquYt+rUnrqrbB0WYRlmLmjW/t5Ll3c52kK/qzU7zrupFH7 R9zUHmUWgeoJuedkVYZH02gg1AbYlUNAUOGev4qreDihVnSSyeKUIrz5SsMWW2/VLVaj l494m+USiTsk9zwHNyEsWvINkZDQjT6OJ9+YGhB8XER1YT3hBJzEyHuafITl4hoxdjph p+qA== X-Gm-Message-State: AHQUAuY+ys1VxK7HTBE7fu+bUjgHX2TTFZGcQzUF69nqk/DoT4IH3J7E 6TE5a6liRi66Ya041FjB5VwMBWxOvjBX/NBkdeI= X-Google-Smtp-Source: AHgI3IZgH4DVzZ2I0uu4xH0ZAcN7OF7FaLU5Lv/EWJXJfys8PpRaSkLyNj/BxyZOxuNbs50JCCHgScGtcVER8vINDnk= X-Received: by 2002:a19:d554:: with SMTP id m81mr22334334lfg.164.1549904172938; Mon, 11 Feb 2019 08:56:12 -0800 (PST) MIME-Version: 1.0 References: <5437a651-8263-49e9-b87e-d8d052d66c99@web.de> In-Reply-To: Date: Mon, 11 Feb 2019 11:56:01 -0500 Message-ID: To: Levi Morrison Cc: "Woortmann, Enno" , internals Content-Type: multipart/alternative; boundary="000000000000aa081b0581a12fbb" Subject: Re: [PHP-DEV] Variadic is_*() functions From: chasepeeler@gmail.com (Chase Peeler) --000000000000aa081b0581a12fbb Content-Type: text/plain; charset="UTF-8" On Mon, Feb 11, 2019 at 11:35 AM Levi Morrison wrote: > >> 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. > > > > Unless you are talking about cases like this: > > if(is_numeric(reallyFastFunc($foo)) || is_numeric(reallySlowFunc($bar))) > > In that case, you might be able to short circuit the evaluation of > reallySlowFunc($bar), which wouldn't be the case with > > if(any_of('is_numeric',reallyFastFunc($foo),reallySlowFunc($bar))){} > > Yes, this is what I was referring to. As previously stated, I don't > think it's likely to be an issue. If it is, then as you stated the > normal boolean logic can be used in such places. > > ----- > > In other words, nothing needs to be done in PHP itself. Just write or > use someone else's `all_of`, `any_of`, `none_of`, etc, functions. > > I'm sure there would be performance enhancement by having it handled with C vs PHP. I would guess you'd probably need to implement separate functions for each is_* variant though: any_numeric, all_numeric, none_numeric, any_boolean, all_boolean, none_boolean, etc. You could probably still have the any_of, all_of, none_of versions as a shortcut though. I'm speaking from a point of some ignorance though in terms of what is and isn't faster when done in C. Whether it needs to be in core/bundled extension is another debate though. Seems like it might be a good thing for someone wanting to learn to write extensions to get their feet wet with, though. I did something similar when I wanted to try out writing an extension. I implemented a left($str,$len) and right($str,$len) method... which are basically just shortcuts for substr*.. but gave me some experience with all of the boiler plate needed, as well as utilizing existing functions. *left($str,$len) => substr($str,0,$len) right($str,$len) => substr($str,-$len); > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- -- Chase chasepeeler@gmail.com --000000000000aa081b0581a12fbb--