Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112477 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48773 invoked from network); 9 Dec 2020 20:33:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Dec 2020 20:33:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AC7891804CF for ; Wed, 9 Dec 2020 12:03:16 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 9 Dec 2020 12:03:16 -0800 (PST) Received: by mail-qt1-f196.google.com with SMTP id f14so1892495qto.12 for ; Wed, 09 Dec 2020 12:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OEaaSSeLBmGWiEiFNdLzJTuQRw1OKSf0BVQSQaVyU4Y=; b=w8KALk+3aJK1ezjgrOq/KcpGzfIGIokgtG7NrJfsY1asVY7stxoOg8v7icG/C2WcpV DvT8VF5eBYaGOZ3ONshLn2JK0dz7S+EvS2L4Vf2Hwuy/uR1xYqffkj2stXRlEfS7E+qB c4jfW3j1g9zeD77H3snP4zPqAIfsH/QeLVm4Genvmojuj3jQ7uhPWapMJeyko9LNxsQa r3CwLbxOXpOeMvqCTnwludhwnIlFpESvcv3brAHFZJzKnqUQif/MwI6vdoTicnRRdR4J op+2ZTQ+bcdgRy5Mb3zcYwGJjU7VkQdOewHZG8YontdIpMsltY4vBs1uv4TNJHK/sqzx BBKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=OEaaSSeLBmGWiEiFNdLzJTuQRw1OKSf0BVQSQaVyU4Y=; b=ulQOOiEcSQ2ZPPqlHz0gViRwUoWhtcV22UDgqfnBblwdHWkXJ/FiiOHqdU1LhiQXz8 odBsbXpv/30MGopl3wwrePcBD5ORBLHEMFimDFijhfBeGMoF6TrUCkwetSo1np/TD6e+ MPB8tAafT5Wox8I3qhC+/UX6w8vO1QnoyPraPCdhX7b9PZzU1Vs8oWy3VSPnTyjNKUl8 ZWtZMMrgoHTPpY5VQRXQisD1NNLkTfl9kqKYN/W4eWbkIUHcuLy3rmB981X4C19067bY oD2rBnJp25+ysJO7NQVMcX83+RTWHntIWXVJfiXrqwfZYZTX6CuJc0t3tCMpVwARjndP pJcw== X-Gm-Message-State: AOAM532DDl7ch438/M+TiQr79wmlkR/YJfLiQnzz7+A+lGZITsWcHrAT X1XhqK5i42N7Mhlxd2mudXHMtg== X-Google-Smtp-Source: ABdhPJwssn5wQNfv0odiYb2ECxM7IZcFTc/CNXEmRF7aByUrh+9hP0m2rGsNsb9PU3gNiH5wJwPDHA== X-Received: by 2002:ac8:16ac:: with SMTP id r41mr5017346qtj.270.1607544193553; Wed, 09 Dec 2020 12:03:13 -0800 (PST) Received: from [192.168.1.226] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id r201sm1895101qka.114.2020.12.09.12.03.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Dec 2020 12:03:12 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: <1150805a-44b0-af7e-d54b-6082fd23a63e@gmail.com> Date: Wed, 9 Dec 2020 15:03:11 -0500 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <1150805a-44b0-af7e-d54b-6082fd23a63e@gmail.com> To: Rowan Tommins X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Enumerations From: mike@newclarity.net (Mike Schinkel) > On Dec 9, 2020, at 2:06 PM, Rowan Tommins = wrote: >=20 > On 09/12/2020 18:47, Mike Schinkel wrote: >> 1. Will enum methods be idempotent? >>=20 >> If not, shouldn't they be? >=20 >=20 > Can you clarify what you mean here? For a given parameter set the method would always return the same value. = Note I am not suggesting that values would be fixed across different = executions, only within a given execution. Said another way, idempotent and deterministic[1] are effectively = equivalent. Taking this example the now() method would not be idempotent nor = deterministic: enum DayParts { =20 case Morning; case Afternoon; case Evening; case Night; public static function now() { $now =3D intval(date('H',time())); return match(true) { $now < 8 =3D> static::Night, $now < 12 =3D> static::Morning, $now < 18 =3D> static::Afternoon, default =3D> static::Evening, }; } } [1] = https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-fun= ctions/deterministic-and-nondeterministic-functions > The only meaningful question I can think of is "can they change the = object's state?" That's mostly answered in the RFC, most notably by = specifying that enums may not have instance properties, to avoid them = having any state to change. >=20 > Unless I'm missing something, trying to define "idempotence" or "pure = functions" any more strictly than that would surely be a massive project = in itself - for a start, you'd need a whitelist of all built-in = operations which were side-effect free (i.e. no file writes, = configuration changes, output, etc, etc). I do not believe it should be a massive project. I believe it could be = implemented with a simple map that takes a hash of the input parameters = and maps to their return value. For idempotency this value should be = calculated the first time the method is called.=20 After the first call every subsequent call would hash the input = parameters, lookup the pre-calculated value from the map, and the just = return it without re-executing any code in the method except for the = return statement (I am considering of the desire to set a breakpoint in = XDEBUG on return for all accesses, not just the first.) The one potential concern is if the number of potential input = permutations is large it could eat a lot of memory if the app actually = used a lot of them. But then that is true on any use of memory in PHP, = so if it became a problem for a developer I think it should be on them = to rearchitect their solution to avoid using too much memory. This is an important question to answer *now* because IF the answer to = idempotency is "no" then restricting it a later to be idempotent would = require accepting a BC break. But if the answer is YES, the restriction = could always be relaxed in a future version if that ever made sense. -Mike=