Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95998 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43667 invoked from network); 14 Sep 2016 17:57:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Sep 2016 17:57:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=david.proweb@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=david.proweb@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.180 as permitted sender) X-PHP-List-Original-Sender: david.proweb@gmail.com X-Host-Fingerprint: 209.85.216.180 mail-qt0-f180.google.com Received: from [209.85.216.180] ([209.85.216.180:33197] helo=mail-qt0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/18-21040-A7F89D75 for ; Wed, 14 Sep 2016 13:57:14 -0400 Received: by mail-qt0-f180.google.com with SMTP id 11so11055661qtc.0 for ; Wed, 14 Sep 2016 10:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=Xk7t8lbj1aL0MrQaOsZSHOb5k5zETOWoDOLVzfAT6e8=; b=Lwj9v46EaJjoC4elh17Z8diVyulU5pnym7ypdwkobxLBrmaivkftj9w8Wv3Y1NC6Cg 2PiDAe4NvkmlTkbEp7EhIeedZR1nCnOu0tB92nb8AtCiDQaXZinI3ruMZbWnkYL1N941 gvLr4BaNdKrxUV3xarnCbI0BUYjEFadMaCEGgjaPEx0pVYqTwDzMvOHQ2aPuuOcC0+VA VP/BRfR8EGqgQkyKnYkMyF6t+2Qf35OycfGOCOsVKf2+yIZy+BWlxGwfq1Pd1BV7GYU3 ayYm38d+x4GJQr09/J53ggCUPcxTXKCe1dSESGwKLJd3JyUmKOhhZL6rGms0bcltrhmL Bqag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Xk7t8lbj1aL0MrQaOsZSHOb5k5zETOWoDOLVzfAT6e8=; b=GHFMIiScP5JyIW79+SUBaxsy6ncIaE+zwJ/CsFMMmHC/LJjqSGFwPPEkFlJMglc2fQ VUyErV8nfQA8J8UhWoZU0Yt/EKYxs/d0X7+x3+Jfc1kJDdmD2fKxucdCqrWgtgkZ6sSx OyKJj15rCxkFiOcrAzLZSv13Nvx5ZmBXI2NUZmmDHYxiQxIIfM/EJjhZhbukC13nNUjq 1vHNCcwO7RVLpq8bQs27WQ+ZGVFhH3PvjIVW84DGrKtwJb3ve6bePx0L+EOufOUSJ5H8 I4O/i9MVNRwLU2IRhinw0PxGOEsfFCf08yzXucmUezp8S3K/0aCejkyKhGKqFwjennWW ppDQ== X-Gm-Message-State: AE9vXwP6edO00oN3l8JADLeYzg++2xis/CzZA2W7hVgzf4NfTKzILenWRiS6BZRC0mR3dD610U3gx40r/+/2vQ== X-Received: by 10.200.49.81 with SMTP id h17mr4657350qtb.48.1473875831365; Wed, 14 Sep 2016 10:57:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.45.67 with HTTP; Wed, 14 Sep 2016 10:56:50 -0700 (PDT) Date: Wed, 14 Sep 2016 14:56:50 -0300 Message-ID: To: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Super-types declaration From: david.proweb@gmail.com (David Rodrigues) There are a RFC for union-types (https://wiki.php.net/rfc/union_types) that was declined, but I see that it is a recurring question here (today, for instance, David Eddy tried to start this discussion again with the same concept). Then, I don't know if the problem is the union methodology like string|int or if it could be useless. In my mind, I think that is very useful, mainly over scalar types (string|int, for instance) or when method could support mixed types of objects. For instance, I have a method called mergeWith($value) that allows $value to be instanceof array or self. Currently I am solving this problem by using assert(), something like assert(is_array($value) || $value instanceof self), but I see that is not the best option. In this case, I suggests to create a super-type that allows to define a super-type (typedef) or inline super-type (union-types). class { typedef MyType (self, array); public function mergeWith(MyType $value) { } } Or, following the union-types (as inline super-type): public function mergeWith(types(self, array) $value) { } public function anotherMethod(): types(self, array) { } -- David Rodrigues