Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98307 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18114 invoked from network); 15 Feb 2017 20:26:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Feb 2017 20:26:37 -0000 Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; 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:44611] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/42-01562-D79B4A85 for ; Wed, 15 Feb 2017 15:26:37 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id BC25B298423A for ; Wed, 15 Feb 2017 21:26:34 +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 s3DBBsWfL14A for ; Wed, 15 Feb 2017 21:26:33 +0100 (CET) Received: from mail-wm0-f53.google.com (unknown [74.125.82.53]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id ED5C12984239 for ; Wed, 15 Feb 2017 21:26:32 +0100 (CET) Received: by mail-wm0-f53.google.com with SMTP id v186so51419512wmd.0 for ; Wed, 15 Feb 2017 12:26:32 -0800 (PST) X-Gm-Message-State: AMke39lbU2SOAvNzzEdGOcSnvwSrS7/b7/GV8nu9Og/ZziYOsOsdFSe1sqK7DNJI4B9tJ1KRoJioIhMdP7qeTQ== X-Received: by 10.28.59.212 with SMTP id i203mr9268408wma.41.1487190392753; Wed, 15 Feb 2017 12:26:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.169.165 with HTTP; Wed, 15 Feb 2017 12:26:32 -0800 (PST) In-Reply-To: References: Date: Wed, 15 Feb 2017 21:26:32 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Rasmus Schultz Cc: Andrea Faulds , PHP internals Content-Type: multipart/alternative; boundary=001a1148f62a12dcec0548977f09 Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object type hint, now with added variance From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --001a1148f62a12dcec0548977f09 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2017-02-15 21:25 GMT+01:00 Micha=C5=82 Brzuchalski = : > 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 the= n > enums would really be closer to classes than values. > And also then could even utilise `object > typehint so it'll accept enums also. (Sorry for second mail - unintended Ctrl+Enter) > > 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, >> this >> >> is >> >> easily solvable by providing a marker syntax for non-object hints. Fo= r >> >> 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 >> > >> > >> > > > > -- > regards / pozdrawiam, > -- > Micha=C5=82 Brzuchalski > about.me/brzuchal > brzuchalski.com > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --001a1148f62a12dcec0548977f09--