Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98001 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38825 invoked from network); 28 Jan 2017 10:51:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jan 2017 10:51:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=giovanni.g@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=giovanni.g@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.65 as permitted sender) X-PHP-List-Original-Sender: giovanni.g@gmail.com X-Host-Fingerprint: 209.85.213.65 mail-vk0-f65.google.com Received: from [209.85.213.65] ([209.85.213.65:32911] helo=mail-vk0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/0F-28703-B977C885 for ; Sat, 28 Jan 2017 05:51:07 -0500 Received: by mail-vk0-f65.google.com with SMTP id t8so23137775vke.0 for ; Sat, 28 Jan 2017 02:51:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/r39xFY5HWbewrp9ITxp+21/H6JzqDVX9RIMURZC5yg=; b=fpJV9hv8YxL1DcuqXVl3jUodFmrDT9n8iPlWvk3af73SB5WImAU0UCMVVkFOP8Dqa+ f7GnN8qCOnKggT2PFk9rTti4ku5lMXvzcY53/YXkj4wC5At4RhQXskVNKKMiZvCrYwdB LdHxug+Sc8myX51QZy50oRd7gPco5lQVFXTdx2aVvyosuuQXyMd2UbQReG68xCscWBcb w/LGKkcsWkzZNobBSUz407AM4fMeRsOu7rSyoKgo81XIqgSQlIJRxjvNo7e1d+dhpRH7 e9Ks/p9lPYYlYizhfl/mqnq3CVGXmoly2+ISSa10bl3N8YzofxQmi1mA0gtoeWuIJK3n 4+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=/r39xFY5HWbewrp9ITxp+21/H6JzqDVX9RIMURZC5yg=; b=uRCerX6iY9gHXe3gmZvHEjxI7SKJjvwHb1WZ1AL03VY/Xyg8ZyIIoH0XVi2A9p6uC8 sYOd6vrFl/OWBGvzQHUBK1c5L7j3GNhj/r/Za9gpqJ5SM8dYlAj0NCO1Cx0lz2AKMK+T oZUfJpb8vwMFLAaWfmY38GM4Bn3TpYHLYgQyAB0apszQBFi5K9iV6S7qps4CaZKx2pcB 4VXrhhNc53fWOr1bUK08uyvhwJoj7/hmydNYybQ1zeIbg8pttEjAtPyiiks7SVx7uuBD FkhSSFuAUgBoGXTAWCcGgPIzXxamXh7659xV0/gHUwO0YQTTGeCeD6qj0YtD2agH1x/i Wnmw== X-Gm-Message-State: AIkVDXJ5Qog4l+ilNwq/2F8cNJi+RoXZPEKuyCByzLel+cVXBcs3sXDlRP4CAuWbUZCr3roWimZY/OT2rqVkOg== X-Received: by 10.31.107.74 with SMTP id g71mr5076716vkc.116.1485600664185; Sat, 28 Jan 2017 02:51:04 -0800 (PST) MIME-Version: 1.0 Sender: giovanni.g@gmail.com Received: by 10.103.125.67 with HTTP; Sat, 28 Jan 2017 02:51:03 -0800 (PST) In-Reply-To: References: <503add40-506e-f8e9-8a4f-59cecc429018@mabe.berlin> Date: Sat, 28 Jan 2017 11:51:03 +0100 X-Google-Sender-Auth: 6OjwHmvpghuUXeBflicRKyVELAc Message-ID: To: Wes Cc: Marc Bennewitz , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11479100ddf2bf0547255bb4 Subject: Re: [PHP-DEV] Allow "static" type From: giovanni@giacobbi.net (Giovanni Giacobbi) --001a11479100ddf2bf0547255bb4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 28 January 2017 at 10:18, Wes wrote: > Hi=E2=80=8B, static could be definitely a valid return type, but I don't = see this > happening for parameters, for the same reasons this is disallowed: > > class A{ function bar(A $a){} } > class B extends A{ function bar(B $b){} } // must be contravariant, but B > is covariant to A > > That's not completely true, the contravariance rule exists to defend the polymorphism and overriding, BUT this is a static scope so it is *almost* like an overloading, I.E. B will have *another* method bar which is different from A's, the only difference is that B should also inherit original's A::bar but it does not, it's like A::bar(A) is not inherited. Before anyone say it, I know you can use the $a::bar() syntax to invoke static methods, but I consider that a shorthand of A::bar() and what people should *always* use unless they have complete control over the code and invocation stacks. I did in fact hit a use for this feature a long time ago where I wanted to have a static method which is able to operate (in my case delete from database) an instance of an object, and I solved it WAY before the introduction of all this syntactic madness I've been witnessing recently, which is: public static function delete(self $object) { $class =3D get_called_class(); $baseclass =3D get_class($object); assert('($class =3D=3D $baseclass) || is_subclass_of($class, $baseclass= )'); // do whatever you need to do } The reason is that I always want the caller to be aware of what he is doing and never use the "standard" method on a subclass which actually redefines it. Even though I like the proposal and I would personally use it, I'm against it because I think PHP has been getting a lot of "features" which only safe a few keystrokes in very edge cases but complicate the language and steep the learning curve, which was the only real strong point of PHP, its simplicity. I think the latter thought is a bit offtopic, one day I will start a thread to start philosophizing on the direction PHP had taken the past years (good old times when the strict type hinting was rejected because it made it too complicated for newcomers, lol). Cheers --=20 Giovanni Giacobbi --001a11479100ddf2bf0547255bb4--