Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105338 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87128 invoked from network); 23 Apr 2019 03:43:14 -0000 Received: from unknown (HELO mail1.25mail.st) (206.123.115.54) by pb1.pair.com with SMTP; 23 Apr 2019 03:43:14 -0000 Received: from [10.132.106.7] (ppp-223-24-161-85.revip6.asianet.co.th [223.24.161.85]) by mail1.25mail.st (Postfix) with ESMTPSA id 287DD603FE; Tue, 23 Apr 2019 00:43:18 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (16E227) In-Reply-To: Date: Tue, 23 Apr 2019 07:43:13 +0700 Cc: Benjamin Morel , Larry Garfield , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable Message-ID: References: To: azjezz Subject: Re: [PHP-DEV] Object Type Casting Reloaded From: php-lists@koalephant.com (Stephen Reay) > On 23 Apr 2019, at 06:30, azjezz wrote: >=20 > Hello Ben. >=20 > yes, i have made a gist with a simple example to show the `as` operator us= age in hack + HHVM ( 4.1.0 ) output. >=20 > see : https://gist.github.com/azjezz/03955ff2b009f1ced22ce68c9a862847 >=20 > Sent with [ProtonMail](https://protonmail.com) Secure Email. >=20 > =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 Original M= essage =E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90=E2=80=90 >> On Monday, April 22, 2019 11:50 PM, Benjamin Morel wrote: >>=20 >> Hi Azjezz, thanks for jumping in! >>=20 >>> I have been using HackLang for quite a while now and i believe they have= a better solution for this, and it would awesome to see it in PHP, the `as`= operator. >>=20 >> If I understand correctly, `as` is an operator that performs type checks b= ut never casts like () does. >> This looks like a serious candidate for an alternative syntax to the one I= proposed! >>=20 >> - Ben I like the idea but I find the syntax (both suggestions) less than great, gi= ven that there=E2=80=99s already =E2=80=9Censure a type=E2=80=9D syntax, and= both suggestions are already used for other things (casting and foreach) Is there some reason (eg ambiguities) a type can=E2=80=99t just be placed be= fore a variable to ensure a type, similar to a function parameter or typed p= roperty? Eg=20 string $foo =3D 'bar'; array $bar =3D getBar(); foreach($bar as int $k =3D> string $v) {...} Cheers Stephen=