Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105361 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18525 invoked from network); 23 Apr 2019 17:02:03 -0000 Received: from unknown (HELO mail-it1-f177.google.com) (209.85.166.177) by pb1.pair.com with SMTP; 23 Apr 2019 17:02:03 -0000 Received: by mail-it1-f177.google.com with SMTP id s3so296734itk.1 for ; Tue, 23 Apr 2019 07:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LiPnUAd42aI8rvRw6vAFf4FEFE+EY2m0CZnbfAZYy2Y=; b=u+tSYuhDtMeCJ0WmqEVUqUzObruwofERID9CfsyzYrunPehjBfzTDFHo1/R9X/Ztpn Z7wo4wu0OuJ91przhKsoggzRUzdmHfglEsf3IVjigzmiGGPEBQNALzAPvnOnOpVn9B8C mTxi0D8AAaImIJ+L+uLEIrsNYZO3uWksLUIlg+YUg0ZJsshFQkHegK8ynRYSzU9krIS5 Tbdq4rOXQpfg32Ad/n9kVEyogkH8WMsRJ8pTS/N74StS0HTmpgZRzzyu0WqZut25qmnt 4MmG/PaQdvAJygvobF+5pRapyxJRI+EIYd4+cMR7u95sf/xUj0WV63wh3YwYY0pfqrtP yavA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LiPnUAd42aI8rvRw6vAFf4FEFE+EY2m0CZnbfAZYy2Y=; b=pVkCSTg0zvFo7PDEzmqj9cpE8UE3FbSOLc+A8AfRBKpOCaITVVaytmOJVAv7e2pcEo Q7/wP+mVaQvDA+20W+sF3nPm+FyPvgkn/YUHEeRgfCRRgkhq1EICbATfSz6V2tnKPh97 3nsz3R6YIhVLTG0W/uLzTrlHvCAFt+6GLX12c4gkTa1ZvGXT7hTvWe2ARiVocCKUCkXk 7z+hObpQBSl4zkRbtBj3K0U5Csirq8WbRjU9fqMNXO/1RjiKUpAzUhb5ovnx0jMjidmN 7yufqhSVoCn19Tkw5tZ0c8mvLjOhvwdQRcySjVBHlpuI4QT9nwsAqBDuBwR9IK2I2KH8 gDEg== X-Gm-Message-State: APjAAAU/FNntKpUhqONO57LfYN4BKbcbEGiF+GDmqfQpQ/lj8YH/CM3j Vi99nPAqxeRzi4neduz+oPh11xWErF5oUU/QlxhniS/JlSk= X-Google-Smtp-Source: APXvYqzwp5BPC/jxa5ZcSkb/LZVQH6Ftz/G0Ns1rQgV/fIhfdc2qEjCdRb1zFo1KYYsDgIe+OMZK1zhnjzfvqFXYlIs= X-Received: by 2002:a02:95aa:: with SMTP id b39mr3793432jai.45.1556028147677; Tue, 23 Apr 2019 07:02:27 -0700 (PDT) MIME-Version: 1.0 References: <9fee0f79-a77d-c0f1-ec24-efa4dd587f91@hristov.com> <71E9312E-C4A6-44EB-AB1C-D8E063EB946A@koalephant.com> In-Reply-To: <71E9312E-C4A6-44EB-AB1C-D8E063EB946A@koalephant.com> Date: Tue, 23 Apr 2019 16:02:15 +0200 Message-ID: To: Stephen Reay Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000000c05a0587330908" Subject: Re: [PHP-DEV] Object Type Casting Reloaded From: benjamin.morel@gmail.com (Benjamin Morel) --00000000000000c05a0587330908 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable @Stephen Reay > And as I said before, I can=E2=80=99t understand how that is supposed to = be better than just doing what works now, using instanceof to check the type inside the block: > if (! $foo instanceof Foo) { throw new TypeError(=E2=80=A6); } > At least with the above, it=E2=80=99s obvious what is happening. It's exactly the purpose of the proposal: avoid this boilerplate. For the same reason you probably write: function test(Foo $foo, string $bar) {} and not: function test($foo, $bar) { if (! $foo instanceof Foo) throw new TypeError(); if (! is_string($bar)) throw new TypeError(); } We could have argued a few years ago that adding type-hints to PHP was unnecessary, for the same reason: if was possible to do these checks in userland. It's just much more readable and concise to let the engine perform the checks. The current proposal is to fill the gap of type checking / type hinting **inline**, when getting data from an losely typed source. - Ben --00000000000000c05a0587330908--