Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98486 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97619 invoked from network); 12 Mar 2017 05:24:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2017 05:24:21 -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:48058] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/A4-38004-D7BD4C85 for ; Sun, 12 Mar 2017 00:24:15 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 7A6BF2984237 for ; Sun, 12 Mar 2017 06:24:09 +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 mK0XmcLw89B6 for ; Sun, 12 Mar 2017 06:24:05 +0100 (CET) Received: from mail-wr0-f173.google.com (unknown [209.85.128.173]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id CE6892984235 for ; Sun, 12 Mar 2017 06:24:05 +0100 (CET) Received: by mail-wr0-f173.google.com with SMTP id u108so85681001wrb.3 for ; Sat, 11 Mar 2017 21:24:05 -0800 (PST) X-Gm-Message-State: AMke39mUgc86X+wv2ZjuxMYlsXY3e2AZdQgsIRI3yydBrkFDVGEwVsiA39hlxyhtLeReTRST9+ZyUGGQu58eQA== X-Received: by 10.223.129.183 with SMTP id 52mr24170371wra.88.1489296245558; Sat, 11 Mar 2017 21:24:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.169.68 with HTTP; Sat, 11 Mar 2017 21:24:05 -0800 (PST) In-Reply-To: References: Date: Sun, 12 Mar 2017 06:24:05 +0100 X-Gmail-Original-Message-ID: Message-ID: To: Michael Vostrikov Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a1148dd42ae9bb0054a81cd49 Subject: Re: [PHP-DEV] Type variants From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --001a1148dd42ae9bb0054a81cd49 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2017-03-11 17:24 GMT+01:00 Michael Vostrikov : > > 'Order does not match OrderForCheckout. Reason: ...'. > > Sorry, this is text for second example) I missed this moment. But I think > the idea is clear. > > > For manual call of __match() type casting can be used: > $orderForCheckout =3D (OrderForCheckout)$order; > > > Also this feature can be used for checking enum values or intervals. > > class Value > { > public $value; > > public function __construct($value) > { > $this->value =3D $value; > } > } > > class State variant of Value > { > const ACTIVE =3D 1; > const INACTIVE =3D 2; > > public function __match() > { > return in_array($this->value, [self::ACTIVE, self::INACTIVE]); > } > } > > function setState(State $s) > { > ... > } > > setState(new State(3)); > > In constructions like "new State($value)" __match() can be called after > __construct(). > > > If to add a possibility to use data types, class Value will not be needed= : > > class State variant of integer > { > ... > public function __match() > { > return in_array($this, [self::ACTIVE, self::INACTIVE]); > } > } > > setState(3); > IMHO the real life implementations always differ, in another case, they would be the same. Example with Rectangle and Square IMO is an example of bad naming in this case. I rather want to call it Quadrangle and have one implementation or event do the simplest inheritation. But I may be wrong. --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --001a1148dd42ae9bb0054a81cd49--