Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119333 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5554 invoked from network); 18 Jan 2023 20:09:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2023 20:09:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20355180547 for ; Wed, 18 Jan 2023 12:09:21 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Jan 2023 12:09:20 -0800 (PST) Received: by mail-ej1-f50.google.com with SMTP id hw16so16288ejc.10 for ; Wed, 18 Jan 2023 12:09:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=rKIM5G1W0SuLiY8ci0l59iJ/AMOdBqWQiDS5xbB3fsc=; b=FSRDjFf35u00zRUpgYDq7vNFSijmPNemOvwahM8lKsv6/6wcraVkSiH64IC/bUMvSE +zaIBF0Lw2KNmlAKiAMqCrIU0XxuxSniAjUX6pLpEElu/9DEgwHo+2AmaSGcRnJabEwU +kw8qlGGK+hZrns4kiRduHzU51LLEMfAunsrBw6X9O62btaITDSQAE1LFpmLsQqr67Ro h1Y5fCymZL1KjhJ/jX6l9/6T00igkP5m7KxZdifqMdJ9iy7lem13zIOWH8TtGQRMiMEi P0Gmy9lIl0K/xDa6oseettfwjVgqUAVwpfeFR6ENR2S5yT5rtpR47CyQf1T+I6TZSeYK 9A5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rKIM5G1W0SuLiY8ci0l59iJ/AMOdBqWQiDS5xbB3fsc=; b=NB+QPeSgoI2U6sdtnlj/BzitEHvkpP7vOQnWUmLC5nBh+YG8J0zjPqb/awCnNOP/gY UZNUxGbIqE8csQMCpbmC6fDrIH2R3Xp1p6TNodPzVRrNitKrpQKfKr7NlR4wjMN+wLYN Fg49TOkB4i8KXZycWd1jDHKKTiFrQx2gACC/BN0vWPgrPEdSVMYrd4TY+mWvtXYZGmPn pw43vd6ESsN3kb9yLqhn305STNJ5RSy9EuQolb/+8STkUP1dRemayfJriNR1qlioxTqg x/KzaMOD2wLcF62eqpooPrxcwOUC+iY+/Al/MkC8/38Y6CJWp5KhZL32pXecrxLPsxGq DEgw== X-Gm-Message-State: AFqh2koPRftkHfrfe0OCiRSnX1t8N0brfVZ05T57WxR8sG6+xfWeh2nV c0z8ePdcgn7h2Dv7pPGH9LA= X-Google-Smtp-Source: AMrXdXs2qdLIlvVMWoyhv5BiVPlEFQmbCAxkdtvYEOaLa2KhdqDVQMDYWt6VGdCHW29bPsCPwRQ+TQ== X-Received: by 2002:a17:906:6a27:b0:872:8c97:db27 with SMTP id qw39-20020a1709066a2700b008728c97db27mr9349235ejc.69.1674072558192; Wed, 18 Jan 2023 12:09:18 -0800 (PST) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id f22-20020a17090631d600b00779cde476e4sm15077743ejf.62.2023.01.18.12.09.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2023 12:09:17 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_7B9D108A-85B3-48CE-87A0-31C469EACBB6" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.300.101.1.3\)) Date: Wed, 18 Jan 2023 21:09:06 +0100 In-Reply-To: Cc: Kamil Tekiela , PHP Developers Mailing List To: autaut03@gmail.com References: <04288995-54CE-41A4-BFFD-A7CF72F16D3F@gmail.com> X-Mailer: Apple Mail (2.3731.300.101.1.3) Subject: Re: [PHP-DEV] [RFC] Path to Saner Increment/Decrement operators From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_7B9D108A-85B3-48CE-87A0-31C469EACBB6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 18 janv. 2023 =C3=A0 19:33, Alex Wells a = =C3=A9crit : >=20 > Classes and methods is the expected way of implementing standard = library in an OO language. New APIs (such as the new Random api) use OO = instead of functions and it makes more sense to use OO in this case too: = there's likely a place for other methods too, like toBase(int = $otherBase) etc. It would also be possible to use overloaded operators = if needed. Fortunately, PHP is not (yet) a language where every problem requires = the use and manipulation of objects implementing a generalised and = unified solution. I guess that the OO way of writing: ```php function next_alpha_id(): string { static $x =3D 'zz'; return ++$x; } function next_num_id(): int { static $x =3D 0; return ++$x; } $my_id =3D next_alpha_id(); $my_other_id =3D next_num_id(); ``` would resemble to the following, except that `mixed` should be replaced = by the use of generics. For brevity, I left the mandatory interfaces as = exercise to the reader. ```php class IdGenerator { =20 protected mixed $current; public function __construct( protected readonly IdGeneratorType $type , protected readonly IdGeneratorDirection $direction , mixed $start ) { $this->current =3D $start; } =20 public function next(): mixed { // implementation... } =20 } enum IdGeneratorType { case alphabetic; case numeric; } enum IdGeneratorDirection { case positive; case negative; } final class StandardGlobalAlphabeticIdGenerator { =20 private static IdGenerator $id_generator; public static function get(): IdGenerator { return self::$id_generator ?? new IdGenerator( type: IdGeneratorType::alphabetic , direction: IdGeneratorDirection::positive , start: 'aaa' ); } } final class StandardGlobalNumericIdGenerator { =20 private static IdGenerator $id_generator; public static function get(): IdGenerator { return self::$id_generator ?? new IdGenerator( type: IdGeneratorType::numeric , direction: IdGeneratorDirection::positive , start: 1 ); } } $my_id =3D StandardGlobalAlphabeticIdGenerator::get()->next(); $my_other_id =3D StandardGlobalNumericIdGenerator::get()->next(); ``` =E2=80=94Claude --Apple-Mail=_7B9D108A-85B3-48CE-87A0-31C469EACBB6--