Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106857 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51505 invoked from network); 4 Sep 2019 18:35:07 -0000 Received: from unknown (HELO mail-io1-f41.google.com) (209.85.166.41) by pb1.pair.com with SMTP; 4 Sep 2019 18:35:07 -0000 Received: by mail-io1-f41.google.com with SMTP id b136so21278717iof.3 for ; Wed, 04 Sep 2019 09:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=YxMYUiGY/PYLw9/Ir+bHtK0HCZJSkohik6ScNclc10w=; b=NaEUnZWFRPQOX18Wr+ZhKzlTvCKDUrsNjt3R4mdbWtYm2Xsjm29OwgfHux0YXXIkxN uT2+kYpABp0PW0YrQbPaV1DNPqkmDVIkX5FpQqx9hbGbEtQEG68t0udy4P+DWnOngFaw qB0SgaDmtHwA7KwarcbBVgceFyKbqF2wJtKEu+DRKquyRIYH2Y1YGSCOE2Drq+d6uVyd 0DJ31Av/HndXN8JcaqyCrm0AAZQ9ymWPI82GR9tr80bUO3kxdvbcM+hK8bu6DtGIEiHk 09zDWDxUoHI0q7GRxYyrRqkSadAalBSd8XrQQXOcin3yQH5Oyue1gkKs115g9aDkV6qC RycQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=YxMYUiGY/PYLw9/Ir+bHtK0HCZJSkohik6ScNclc10w=; b=AU6k4yOFV+xtH2E/TDSODaHFVp4pTPtnmsDdxLAQcBv0g6mz5QrL9Qfvt4Y2MaU535 /IcONz9b9rvgNTKLxDm+i54gVEJuR0XPIC80pb5yAJ4jqBQ1tM5LoGxFC92/xai/NA4K 5qp0JP2+9eKMqmuwEWLaacy0yieozNWTXPY39LRQbA2NEq42pUBngQIqyge9JyO75xJz s7lFgXsg0pbpTWXZVYXNkFa6ezBZ6tYw8sAIySA6TFgtp9d7EEfxxBG8ZwWvIfgcsvco M5dGJS7TLVySpzXIkgZpJUMkchVJXLyW9tIiD8lQ1BVyMpW6slbsAcCGIVpFRi1I1CmJ N2bA== X-Gm-Message-State: APjAAAU9tyBV5HFBOtoeHVCsW3yyQm6WntV/h3pf9mlFmPDzK/517c4k xf1DRpWjOZuL8f1nxx6fDFytEQ== X-Google-Smtp-Source: APXvYqy6uSzCdmd/ZXR08mI7VvSrKD/UA86P/V+Eci7BFfz83RYJx2zZ42bDvB4at+S58VIOt+OBww== X-Received: by 2002:a6b:7215:: with SMTP id n21mr19886430ioc.238.1567613342930; Wed, 04 Sep 2019 09:09:02 -0700 (PDT) Received: from [10.10.42.56] (h96-61-170-50.lvrgtn.dsl.dynamic.tds.net. [96.61.170.50]) by smtp.gmail.com with ESMTPSA id e139sm11084322iof.60.2019.09.04.09.09.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Sep 2019 09:09:02 -0700 (PDT) Message-ID: <41AF2CFB-BB90-40B6-AB21-2710E46CFC56@benramsey.com> Content-Type: multipart/signed; boundary="Apple-Mail=_4DA37704-D2F9-4281-BC4B-5BEB77098739"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Wed, 4 Sep 2019 11:09:01 -0500 In-Reply-To: Cc: Lynn , =?utf-8?Q?Micha=C5=82_Brzuchalski?= , Fwentish Aelondes , PHP Internals List To: Andreas Hennings References: X-Mailer: Apple Mail (2.3445.104.11) Subject: Re: [PHP-DEV] Silent Types From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_4DA37704-D2F9-4281-BC4B-5BEB77098739 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Andreas Hennings wrote: >=20 > In some other languages the mixed type is called "variant". > https://en.m.wikipedia.org/wiki/Variant_type > I mostly remember it from VisualBasic. Union types are probably better than specifying a variant or mixed type. = At present, parameters and properties with no type specified are mixed = by default. Nikita has just opened discussion on a new union types = proposal in another thread. > Fwentish Aelondes wrote: >=20 > Hello internals, >=20 > Zeev's idea to bring peace to the galaxy seems like a good idea, but > impossible to implement in practice. >=20 > But it got me thinking about how one might introduce static typing > into a dynamically typed language w/out breaking BC. >=20 > And then I had this crazy idea: >=20 > //int > $i =3D 0; >=20 > //string > $c =3D 'c'; >=20 > //float > $pi =3D 3.14; >=20 > If static typing in php was *only* an opt-in kind-of-thing, would this > work? Could the parser be built to identify 3 or 4 different keywords > in comments and give warnings or fatal errors for type conversions of > variables that have the type specified in the immediately preceding > comment? Static analyzers (like PHPStan) already honor types specified in = comments above variables. /* @param int */ $i =3D 0; > Micha=C5=82 Brzuchalski wrote: >=20 > IMO it's crazy idea and we should not change the way comments work > especially inline comments which even aren't kept in opcache. >=20 > I think better approach would be to put type in front of first = variable > declaration like: >=20 > [type] $variable =3D $value; I think specifying the type in front of the variable is the best option, = and we have precedence for this with typed properties in PHP 7.4. Cheers, Ben --Apple-Mail=_4DA37704-D2F9-4281-BC4B-5BEB77098739 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCXW/hnQAKCRCwLZeYnIwH G1NnAP9eYmE0iAyqj29n5MIqW+5bDfLjCZLMDneii4E1+csHSQD+J6g2uTFqZ/hi jVyx1iPg3qL+svV+YWxgUEZbxDxqFBM= =19hp -----END PGP SIGNATURE----- --Apple-Mail=_4DA37704-D2F9-4281-BC4B-5BEB77098739--