Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96580 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22283 invoked from network); 24 Oct 2016 06:45:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Oct 2016 06:45:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=php-lists@koalephant.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php-lists@koalephant.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain koalephant.com designates 206.123.115.54 as permitted sender) X-PHP-List-Original-Sender: php-lists@koalephant.com X-Host-Fingerprint: 206.123.115.54 mail1.25mail.st Received: from [206.123.115.54] ([206.123.115.54:45803] helo=mail1.25mail.st) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/A8-28528-FEDAD085 for ; Mon, 24 Oct 2016 02:45:04 -0400 Received: from [10.0.1.23] (unknown [183.89.42.34]) by mail1.25mail.st (Postfix) with ESMTPSA id 271606049A; Mon, 24 Oct 2016 06:44:50 +0000 (UTC) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: <25d4a92c-e1d4-a420-d143-e66eaa8344ab@gmail.com> Date: Mon, 24 Oct 2016 13:44:44 +0700 Cc: =?utf-8?Q?Micha=C5=82_Brzuchalski?= , PHP Internals List Content-Transfer-Encoding: quoted-printable Message-ID: <89D29CE4-3E2E-4421-9E79-17D0F10A733B@koalephant.com> References: <1e7da1db-9fc6-a3ce-9cba-b219af2dd7d4@gmail.com> <7F1CFE1E-48A4-450E-BFD5-645100A16AE9@koalephant.com> <6b490ba3-ad2d-2a2b-9117-de53ce7fea7f@gmail.com> <6954f170-bd74-310f-9ae2-23bda498603d@gmail.com> <25d4a92c-e1d4-a420-d143-e66eaa8344ab@gmail.com> To: Stanislav Malyshev X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Object type hint From: php-lists@koalephant.com (Stephen Reay) > On 24 Oct 2016, at 13:12, Stanislav Malyshev = wrote: >=20 > Hi! >=20 >> I didn=92t suggest we add anything because why not. Knowing something >> is an object is quite similar to knowing something is an array, and >=20 > That's the point - it's not. Array is just an array, all arrays are = the > same inside. Objects are all different, SPLFileInfo object has nothing > in common with PDORow object and with GMP number object. The internals are irrelevant if you just want to check/read a public = property. >=20 >> I honestly don=92t see the difference between the following (except >> that one is currently possible without extra is_* type checks): >>=20 >> foo(array $bar) { if (array_key_exists(=91something=92, $bar)) {=85} = } >>=20 >> foo(object $bar) { if (property_exists($bar, =91something=92) {=85} } >=20 > I'm not sure how adding "object" helps here - now instead of checking > when you call property_exists you need to check when you call foo(). > Same is achieved with is_object, and virtually in the same space. And > also, why would you just check for properties of random object? What's > the point of checking if GMP number has property "zyx" and the same = for > SPLFileInfo, in one function? If you know (e.g. because of type hints, return types, or even object = creation) that you have an object when you call foo(), no, you don=92t.=20= Thats the whole point of type hints, surely: to remove the need to have = manual is_* calls all over your code. >=20 >> So to carry on from that, how is the above not less boiler plate >> than: foo(object $bar) { if (!is_object($bar)) { throw new >> \InvalidArgumentException(=91foo expects parameter 1 to be an object, = =91 >> . gettype($bar) . =91 given=92); } if (property_exists($bar, = =91something=92) >> {=85} } >=20 > You can invent even longer code to show how hard it's to use php > functions. I don't think it would make it very convincing. Adding > language construct for it is like adding language construct for "throw > exception if this variable equals to 0". Surely, it may be useful in > some cases, but in most cases it's not adding anything and just adds > clutter to the language and to the code. It really isn=92t, simple equals tests don=92t require any boilerplate = to be type safe. Or perhaps you=92d argue that `=3D=3D=3D` is = unnecessary because you can just do `is_int($foo) && $foo =3D=3D 2` = instead of `$foo =3D=3D=3D 2`? > I understand there's a fashion that says if you have types on your > variables that's always better, but I don't subscribe to this, > especially when types are as generic as "object=94. Your voting history on type-related RFC=92s makes your opinion on = anything related to user-land types pretty clear. I=92m now done = debating this with you - you=92re clearly going to vote no again = regardless of what anyone says, so I=92ll bid you a good day. > --=20 > Stas Malyshev > smalyshev@gmail.com >=20