Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87126 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94935 invoked from network); 13 Jul 2015 00:12:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2015 00:12:31 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lerdorf.com designates 209.85.220.51 as permitted sender) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.220.51 mail-pa0-f51.google.com Received: from [209.85.220.51] ([209.85.220.51:35254] helo=mail-pa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/02-17022-D6203A55 for ; Sun, 12 Jul 2015 20:12:30 -0400 Received: by pactm7 with SMTP id tm7so197022675pac.2 for ; Sun, 12 Jul 2015 17:12:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=jhE++KT4ryda/BaUbvrAGq3mWjkFBJ/lJMCxPMjtDiQ=; b=J7UQDfHpPx6yt9dHLUuOKha/HrMVUCS8tmiLXC8voisi7pM1zmISv5jNUBF2RQ5Rtg RFKOSGL0b3rx2Hr8o/RQaZNeWSyyYl0ibfRdBg3amema+n4FuL4qP4BbS7k20bMCGV1z rF2DV+nO1tgH2ng/wc0n/g4O+iyeMnOWcLvFI36YQ43k+R5GQ7x3XK3GhnPq375b8xHX PKh9XO+YFDo0zXx4KfTZDttm9mkzFnwLNkf7tJpOztRiyAE8hC9NGNBpag58oApSS39j OEfk023OjvXST8WBLPneoqOnjjABzJ0dRtP5L50u7jONysxQ2zyxi1QRA2lQU+4akYba Y1PA== X-Gm-Message-State: ALoCoQlMgW9W/jBqhQ8O7x+9ZdrFaLhY8baSGmTtnrdpnhl5wspirGKsyKUgFrXH1fDyUcKoKSuP X-Received: by 10.66.141.74 with SMTP id rm10mr62356958pab.96.1436746346337; Sun, 12 Jul 2015 17:12:26 -0700 (PDT) Received: from [192.168.200.14] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by smtp.googlemail.com with ESMTPSA id j2sm16688888pdk.21.2015.07.12.17.12.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jul 2015 17:12:24 -0700 (PDT) Message-ID: <55A30267.10204@lerdorf.com> Date: Sun, 12 Jul 2015 17:12:23 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Larry Garfield , internals@lists.php.net References: <55A16375.4000707@php.net> <55A220D8.3090004@gmail.com> <55A2C1F2.8000301@garfieldtech.com> In-Reply-To: <55A2C1F2.8000301@garfieldtech.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VGbVC48uCTm2ibs5GAuejCrgwEgwEeoR4" Subject: Re: [PHP-DEV] PHP7 and types From: rasmus@lerdorf.com (Rasmus Lerdorf) --VGbVC48uCTm2ibs5GAuejCrgwEgwEeoR4 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 07/12/2015 12:37 PM, Larry Garfield wrote: > I don't know why we're even talking about IDEs here. IDE > auto-completion isn't the point, anymore than it was the point for > scalar type hints or return type hints. It's about the language doing > type checking for you and static analysis, so that the language can fin= d > bugs for you. Eg: >=20 > class Foo { > public Bar $bar; > } >=20 > $f =3D new Foo(); > $f->bar =3D new Baz(); // This line is clearly wrong and the compiler c= an > check it for you. >=20 > That's what the benefit would be. Easier IDE auto-completion is a nice= > extra, but not the main goal. >=20 > +1 from me in 7.1. I am not sure static analysis is a great argument for it either. A static analyzer can read the docblock really easily too since it is part of the AST node for the property. In fact I just wrote one. Feeding it your code example: % cat -n test.php 1 bar =3D new Baz(); % ./phan test.php Files scanned: 1 Time: 0.11s Classes: 2 Methods: 0 Functions: 0 Closures: 0 Traits: 0 Conditionals: 0 Issues found: 1 test.php:9 TypeError property is declared to be bar but was assigned Baz Plus, without union types, doc-comment typing is much more convenient when it comes to running a static analyzer on real-world code since limiting everything to a single type is often impractical. If you grep through existing code in the wirld, you will find a ton of Bar|bool, Bar|Baz|bool|null, etc. I'm not against the idea, but it is quite different from the existing type checking since this is a type check that would need to be done on every assignment for it to make any sense at all and not just at call boundaries like the existing ones. It may not be feasible to do in an efficient manner. A static analyzer can get away with catching 95%. A core language feature can't. Having to do these the type check on assignment will likely require some significant changes to the engine. -Rasmus --VGbVC48uCTm2ibs5GAuejCrgwEgwEeoR4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlWjAmcACgkQlxayKTuqOuBxowCfW4/ca0AMYYvs9ixNtv4toU3t RX4An0FfIhV0wWkL/vNwDIcLNUZOSytD =iwij -----END PGP SIGNATURE----- --VGbVC48uCTm2ibs5GAuejCrgwEgwEeoR4--