Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105363 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34339 invoked from network); 23 Apr 2019 17:53:57 -0000 Received: from unknown (HELO mail-io1-f44.google.com) (209.85.166.44) by pb1.pair.com with SMTP; 23 Apr 2019 17:53:57 -0000 Received: by mail-io1-f44.google.com with SMTP id r10so8887443ioc.8 for ; Tue, 23 Apr 2019 07:54:21 -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=Ylh3VJO4WrjBxL02agRBYQKnyWPnAllFLVYrBT0e5z4=; b=K6+4okUD6u2IcNiMDW7fDo+ZN+xCX0wDeWSkLg5sf+2cTxGoo6pbo8tajeF81JWEQx 0vnWWuO1iHkeIwlyXw8AFsYsc8pkG69lRW2h99Kd5qrQkezHWHy76a8WiBAbK1MzYk/P cQO8Ypos/S7U5fXASKCyS3gXf/T2Ne69zZHeZ2Soni6v5PCqO6Mb1P3lsT3k0FUrResh iyXBja+ye4WktO2Hi4db8uuA5ESWEr8FbSiVogmalJWbJLXasciA+OnDyXcWN1zQQhX6 D+ZrSY9uWDYoQNtSIrM997F9UtVuK1DhuoJD5Xx5tfsFe1pRATVJWD5yai941myiqlaN RTZA== 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=Ylh3VJO4WrjBxL02agRBYQKnyWPnAllFLVYrBT0e5z4=; b=BtUSukrCSNMJxyeAtDG/t5xRUt3RghZU3h/62suFjX+IIp005oSXmo3sGn55KDca4s 6XsJv7sriki3NWIGCp2q+Vu852gl32xgez57eF+LJWf51OGFVXMFAq2Qqu5yONHJryME dnWQVX6r2oWvndAmo2Xa0Y9OSTnJduNo6f+LqGNrH3SwkPuoDuks/pMjpYCdYbOLhEGM xGTbkSgpilgEuwJUuD15i+3Zi7Dh2nJludGHzRPodl/GEOj3sUEaXbVTkx7IlpYfVnqk 7FOR4FqurW6lPKdz6KlFWtzjTPq6hD06DjzftrWLzRon+uvWGtAAKWHLqnWUOgfq0C1k ZCmw== X-Gm-Message-State: APjAAAUMO6ruv1kjj0fzX+91t9uuX6Yyzy/TTnoTDfkcqomLT4YUmmfD 18pE328wJLC68MIzico2NhIgEIjEvxRDcemKyDI= X-Google-Smtp-Source: APXvYqy34ho9R1NJSIKIhegNuwaN46UaEgbhRfLN3zjTsGdYWFovW/Hk+jsqj3FC6VTgQqHtDznIll/tuL1LZIWlslQ= X-Received: by 2002:a5e:a60c:: with SMTP id q12mr6370787ioi.174.1556031261390; Tue, 23 Apr 2019 07:54:21 -0700 (PDT) MIME-Version: 1.0 References: <9fee0f79-a77d-c0f1-ec24-efa4dd587f91@hristov.com> <71E9312E-C4A6-44EB-AB1C-D8E063EB946A@koalephant.com> <91A050D6-0755-4CE4-BE1C-01BDCC618EA1@koalephant.com> In-Reply-To: <91A050D6-0755-4CE4-BE1C-01BDCC618EA1@koalephant.com> Date: Tue, 23 Apr 2019 16:54:09 +0200 Message-ID: To: Stephen Reay Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000983c1d058733c2d5" Subject: Re: [PHP-DEV] Object Type Casting Reloaded From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000983c1d058733c2d5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable @Stephen Reay > In languages without type hinting (e.g. JavaScript) - the =E2=80=9Cboiler= plate=E2=80=9D you=E2=80=99re trying to remove is also common, e.g. using `typeof` in Java= Script. It's also very common to *not* check types in JavaScript... I assume the absence of type hints is partly responsible for this, and a reason why quite a lot of JS developers turn to typed preprocessors, such as TypeScript. > Assigning a variable to itself, because you want to check its type is the weirdest concept I=E2=80=99ve heard in a long time. I assume you're speaking of the foreach() example; sure, used this way, it looks like a self-assignment, but in most cases it's not, it's an inline, checked type-hint: // (assuming the 'as' syntax, now that the cast syntax has been buried) $foo =3D $entityManager->find(User::class, 123) as User; You're effectively adding, **inline and with just a few chars**, an additional type-hint and runtime check to the value. I wouldn't call this a no-op. > You want to add more capability to enforce type checking - I get that, and I share that goal. But when we already have pretty common, intuitive syntax to do so in one situation, I don=E2=80=99t see why you wouldn=E2=80= =99t adopt the same syntax elsewhere. While I don't agree with you on many points, I appreciate that we share the same goal somehow, and hope that we can find common grounds. I would personally not be against variables typed on declaration, but even though this probably does not make sense, I'm somehow more comfortable with: function test(string $name) { $name =3D 123; } than: string $name =3D 'Ben'; $name =3D 123; I guess that I could be more comfortable with this approach if we had a switch, such as `declare(locked_types=3D1)`, that would enforce the type of the variable throughout its lifetime. This may come at a huge runtime cost, though. - Ben --000000000000983c1d058733c2d5--