Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105357 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8022 invoked from network); 23 Apr 2019 16:39:31 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 23 Apr 2019 16:39:31 -0000 To: internals@lists.php.net References: <9fee0f79-a77d-c0f1-ec24-efa4dd587f91@hristov.com> Date: Tue, 23 Apr 2019 14:39:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Posted-By: 94.0.205.114 Subject: Re: [PHP-DEV] Object Type Casting Reloaded From: markyr@gmail.com (Mark Randall) Message-ID: On 23/04/2019 13:32, Benjamin Morel wrote: > Aw. I did not think about a possible conflict here, thanks for bringing > this up! It keeps coming back to the feature we've all been praying to the PHP Gods for... generics. function cast(object $obj): T { if ($obj instanceof T) { return $obj; } throw new InvalidArgumentException('Cast expected ' . T); } $x = cast($obj); -- Mark Randall