Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98306 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16742 invoked from network); 15 Feb 2017 20:25:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Feb 2017 20:25:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain brzuchalski.com designates 188.165.245.118 as permitted sender) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:44312] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/F1-01562-239B4A85 for ; Wed, 15 Feb 2017 15:25:24 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 84A0A2984239 for ; Wed, 15 Feb 2017 21:25:16 +0100 (CET) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sCyN-5OGwVgh for ; Wed, 15 Feb 2017 21:25:11 +0100 (CET) Received: from mail-wm0-f53.google.com (unknown [74.125.82.53]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id F229D2984233 for ; Wed, 15 Feb 2017 21:25:10 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id r141so586724wmg.1 for ; Wed, 15 Feb 2017 12:25:10 -0800 (PST) X-Gm-Message-State: AMke39lycmjeHCAW+3AdscdtAyrr7+cnhDU7qSW93qVrkVjToIgmVxwB2TSu2HR+sdHN4XghXG9ZCZ1oWnJw3Q== X-Received: by 10.28.165.196 with SMTP id o187mr9189965wme.6.1487190310668; Wed, 15 Feb 2017 12:25:10 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.169.165 with HTTP; Wed, 15 Feb 2017 12:25:10 -0800 (PST) In-Reply-To: References: Date: Wed, 15 Feb 2017 21:25:10 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Rasmus Schultz Cc: Andrea Faulds , PHP internals Content-Type: multipart/alternative; boundary=001a114b443c2e57610548977a43 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object type hint, now with added variance From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --001a114b443c2e57610548977a43 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Assumming they would be closer to immutable objects they may have some usefull... I was gonna say methods but the term doesn't fit to enums. But using one of my favourite userland implementation such as `esky\enum` package there are ways to create enumeration from value or from name. Those methods are quite usefull when converting user data passed in request from string to enumeration. Given the example: enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY } When using passed from request data proper enumeration could be restored for eg. $_GET['day'] =3D 'MONDAY'; $day =3D Day::fromName($_GET['day']); // Day.MONDAY or by value $day =3D Day::fromValue(0); // Day.MONDAY Think of it as possible way of restoring from primitive types because then enums would really be closer to classes than values. And also then could even utilise `object 2017-02-15 20:53 GMT+01:00 Rasmus Schultz : > In the light of this, maybe enums (assuming this feature comes first) > should be implemented as immutable objects rather than values? > > Type-checking for enums would be important, so in PHP terms, an enum > "instance" would likely be closer to an object than a value in nature > anyway. > > The way I look at it, this feature doesn't prevent enums from happening, = it > just changes the design parameters. > > Just a thought. > > > On Wed, Feb 15, 2017 at 4:34 PM, Andrea Faulds wrote: > > > Hi Marco, > > > > Marco Pivetta wrote: > > > >> > >> Since the engine is clueless about types until autoloading happens, th= is > >> is > >> easily solvable by providing a marker syntax for non-object hints. For > >> instance `function foo() : enym:MyEnum {}` > >> > > > > If we're going to do prefixes for non-classes, we might as well copy C > > outright: `enum MyEnum`. > > > > Thanks. > > -- > > Andrea Faulds > > https://ajf.me/ > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --001a114b443c2e57610548977a43--