Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97998 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4771 invoked from network); 27 Jan 2017 21:54:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jan 2017 21:54:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=dev@mabe.berlin; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dev@mabe.berlin; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mabe.berlin from 80.237.132.167 cause and error) X-PHP-List-Original-Sender: dev@mabe.berlin X-Host-Fingerprint: 80.237.132.167 wp160.webpack.hosteurope.de Received: from [80.237.132.167] ([80.237.132.167:46578] helo=wp160.webpack.hosteurope.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/7C-28703-971CB885 for ; Fri, 27 Jan 2017 16:54:02 -0500 Received: from dslb-094-222-183-105.094.222.pools.vodafone-ip.de ([94.222.183.105] helo=[192.168.178.53]); authenticated by wp160.webpack.hosteurope.de running ExIM with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) id 1cXESz-0004ex-Dx; Fri, 27 Jan 2017 22:53:58 +0100 To: "internals@lists.php.net" Message-ID: <503add40-506e-f8e9-8a4f-59cecc429018@mabe.berlin> Date: Fri, 27 Jan 2017 22:53:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-bounce-key: webpack.hosteurope.de;dev@mabe.berlin;1485554042;4c442255; X-HE-SMSGID: 1cXESz-0004ex-Dx Subject: Allow "static" type From: dev@mabe.berlin (Marc Bennewitz) Hi all, I would like to know your opinion about using "static" as type-hint similar to "self" and how simple / complex it would be to implement. Example - using static: https://3v4l.org/XqDma class Base { public static function test(static $obj) : static { echo get_class($obj) . "\n"; return new static($obj); } } class Ext extends Base {} $base = new Base; $ext = new Ext; Base::test($base); Base::test($ext); Ext::test($ext); Ext::test($base); Example - using self: https://3v4l.org/Tp7k6 - Boilerplate code to check if the given argument is an instance of static - No way for IDEs to test Ext::test returning an instance of Ext class Base { public static function test(self $obj) : self { echo get_class($obj) . "\n"; if (!$obj instanceof static) { throw new InvalidArgumentException(sprintf( "Object (%s) must be an instance of %s", get_class($obj), static::class )); } return new static($obj); } } class Ext extends Base {} $base = new Base; $ext = new Ext; Base::test($base); Base::test($ext); Ext::test($ext); Ext::test($base); Thanks Marc