Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101942 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30282 invoked from network); 1 Mar 2018 00:34:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Mar 2018 00:34:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wm0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:33954] helo=mail-wm0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 28/BD-25585-C9A479A5 for ; Wed, 28 Feb 2018 19:34:36 -0500 Received: by mail-wm0-f44.google.com with SMTP id a20so28556180wmd.1 for ; Wed, 28 Feb 2018 16:34:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=M6Zd1u0UlqXAhMGqELY7FamZgLoog0UyVwYnm/tCZRQ=; b=eGKpttcZFmSdqFLUodPTOby6mI0ycBRx5LlGf+3d7nI6/RQDXzT8RVwBGAGqIGjZxP DP64dlGqz3LcwCppjBWoDLYTSBrlKyio2t7bltnw63HQIXa+XsDsUxI7dd20I/gbXuyS QaYbMCInJ54T/l3ba60/Ndkoo4BhSwUJeU671UGi69jPFdFE/0YKMe65d8q1AHDHG/mJ F02COdL8f+3lwnlsYPnvVm62GLBfk2uAj5SkLYEM4fk4IXwQ5hcemLGnTE163apXTH9y IBNTelrOt5zZq7iEQmctkpAsKwrRIqG3R8d/tANw93XMARqYKk4oTg/8LX6GnWyjRneL jzvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=M6Zd1u0UlqXAhMGqELY7FamZgLoog0UyVwYnm/tCZRQ=; b=iLFtrQobHgfFwjtJ52WJ3/NnZEURKQeKufJFve5ymyTbaUoZDqDThJVtj8Bdr0O9cC MQPIOu6FLmprKl/gQd/LMBbs9JB1EF4+hmXptxREr+1D1TWEpK2p9HqoZcklXiSXpiGf xk/FyW52glvRV3jrQeMvZ9+pMRdyz7Wl9FrHqnCja8Qqkez7Y0Yhxd/NS6S097f11cX8 PSUhjtBYovyOENxo/YBQPWBrAjBQGhvcvo17g/GtZgxeu0Cm588FELzX3FU77bvRv3an BKR0jXO70QCP8fCAabZp9TYWIdyRKfMU+tGqB5lmIe9YJEXGe17WwyHfNPHUP6B7Vekf 8wiw== X-Gm-Message-State: AElRT7Fvt/DhiAjejW7QxTNUx+KyOoDXp0FHkLB6sLuKD3FcOShxNDRH j0KMXlXC+GN+F2/8G4aGclgpFy37ftXB0MRw5QA= X-Google-Smtp-Source: AG47ELvaBB6VfkaCNwkFHwNcM4ftYRiP/HExrpTI+wSwb4KG5WR2krCi2lWT33MbzIxyqds+bxV0iwJqb7n/DzlWPzc= X-Received: by 10.28.6.205 with SMTP id 196mr269550wmg.136.1519864473475; Wed, 28 Feb 2018 16:34:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.176.177 with HTTP; Wed, 28 Feb 2018 16:34:31 -0800 (PST) Received: by 10.223.176.177 with HTTP; Wed, 28 Feb 2018 16:34:31 -0800 (PST) In-Reply-To: References: Date: Thu, 1 Mar 2018 01:34:31 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals List Content-Type: multipart/alternative; boundary="001a11442ae20c620e05664f0671" Subject: Re: [PHP-DEV] Traits with interfaces From: ocramius@gmail.com (Marco Pivetta) --001a11442ae20c620e05664f0671 Content-Type: text/plain; charset="UTF-8" This cannot work for a number of reasons: - a trait is not a type, and does not practically exist at runtime - trait defined API can be imported with changed/aliased names, breaking therefore the contact defined in the interface - due to the previous point, inheriting a type from a trait becomes a dangerous BC boundary, easily broken by consumers of the trait when consumers alias or when the trait implementor adds a new interface implementation My general suggestions: - don't use traits - don't use traits - also, don't use traits - remember to not use traits - traits: don't - things you shouldn't use on Betelgeuse and other systems: traits Besides jokes, inheriting signatures together with implementations (inheritance, abstract types) is less and less endorsed in the PHP ecosystem, as it just increases coupling by a huge lot. At least from my own experience, things are finally moving towards more composition over inheritance. On 28 Feb 2018 21:58, "David Rodrigues" wrote: > Why traits doesn't supports interfaces (via implements) like classes does? > > It could be useful when trait implements part of abstract functions from > interface, then the class that uses this traits should implements the > another part. > > It could turn it possible (pseudo-code): > > interface VisibilityControlContract > - public function isVisible(): bool; > > trait VisibilityControlTrait implements VisibilityControlContract > - public function isVisible(): bool { ... } > > class UserModel (not need implements VisibilityControlContract directly) > - uses VisibilityControlTrait; > > var_dump(new UserModel instanceof VisibilityControlContract); // true > > The disvantages that I can see with that is that without an IDE I could not > identify easily if interface was implemented by some trait. But it too > happen when I do implements an abstract class that implements some > interface. > > -- > David Rodrigues > --001a11442ae20c620e05664f0671--