Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102840 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74657 invoked from network); 16 Jul 2018 11:14:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2018 11:14:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-io0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:47049] helo=mail-io0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 17/18-39793-EFD7C4B5 for ; Mon, 16 Jul 2018 07:14:06 -0400 Received: by mail-io0-f174.google.com with SMTP id i18-v6so21669544ioj.13 for ; Mon, 16 Jul 2018 04:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=GIjPA8O0U8RzGlPlhQNyYO+/ZD81Gmp/dt5LGsCH88s=; b=ufpsB3j+zsGWoHklrx14SP5tL1d0nvkVclb+Ln9XQHkaafotTJMGTdrVyZ73Qd7Ec/ 58hM6902OH4GHBOZf1L1e2KboyIzn5zmo8YCpYSY/TzFeo1JL3IASM2azCGsxlK12EQ+ YUA2d6/nGbik012PNSqaoP15QMEyg+tBa/x6EaOh+wMfy6p/T1Ohv8+wEfY/nfTTDrUe pGZXwreh6PFvXh1DFUZxFgJPmgmthMbNxGzxGOCAHNMkSjyUBns9qjvU7i5omPKyrsdS 5i4gIlBfTSWRk7Rznkvie8LwcjrCJx0aBoibukISZ/77lxZIAm9lc0BIlr8Y/BHUtbJG js2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=GIjPA8O0U8RzGlPlhQNyYO+/ZD81Gmp/dt5LGsCH88s=; b=U23OMnVRLTP2BqLKmXt3BPIwtMI19zhXNSDQq9B2t6Yxnn+XLMnCCIqD9Rd6an9KEJ Mm7876CTsXhS5wGFPrnZB/civnjYQQM0t1Owi+xDABb4cmxCHLgbA7zUr6KgSj+wA0Yr W4hoU1Ckw9bBAueJIryVK7teOkTvKEFD0zRdK9886c0dp9DQLOAXY0iG6uY5bIvFagXv LPTOCcW2QNXMedr9+E33naDJDkdC+NOxQBgoOF1BEGo+djHTYNHF6TStKbo/PczjEmnG Fg3/A0Bmgt6uKDD+A77M61jeBQKSUkZCY0OXCqTXyCHBt4G6WCwqshz3ow21PsrMu7Xf uehg== X-Gm-Message-State: APt69E1a8fi6ISrLboDLaO4B4DFfw2yyVqjPPxW+Ki/ksT3hnYm9Yb5d zF2szAchM7a263ZgWniXgojVVRn/gTqyw4E6Jgg= X-Google-Smtp-Source: AAOMgpd1MXS0xPEKq0SuWhJuErkqr9duVytwiPIJUI5mLJHnKJiMidZrNdGzZJoZdmBQS5OgfUQlTlS17S4t67wolts= X-Received: by 2002:a6b:c844:: with SMTP id y65-v6mr39166051iof.187.1531739643653; Mon, 16 Jul 2018 04:14:03 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:148a:0:0:0:0:0 with HTTP; Mon, 16 Jul 2018 04:14:03 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2018 13:14:03 +0200 Message-ID: To: Zeljko Mitic Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000059328f05711bed88" Subject: Re: [PHP-DEV] [RFC] Optional typehint check for parameters From: nikita.ppv@gmail.com (Nikita Popov) --00000000000059328f05711bed88 Content-Type: text/plain; charset="UTF-8" On Sun, Jul 15, 2018 at 9:39 PM, Zeljko Mitic wrote: > PHP is dynamic language and each typed typehinted parameter has to be > checked every time. I am suggesting new php.ini value "typecheck.enable = > 1" which can be turned off. > > Example: > with default php config, a code like this would check each member of $users > array: > > function demo(User ...$users) {} > > but with "typecheck.enable = 0", same code would be treated like it was > written this way: > > function demo(...$users) {} > > Basically, php would simply *ignore* typehints and work like they are not > there. > > It would be programmers responsibility to send correct values but people > using typehints are not those still learning the basics. > > Just like it is programmers responsibility to restart php-fpm when using > opcache.validate=0, it would be theirs responsibility to send correct > values. Any decent IDE would mark errors for wrong parameter type and with > tools like phpstan, it is almost impossible to make one. Only development > computers would need to have this checks turned on. > > This creates no BC problems as it is a new feature. Given that typechecks > can be turned off, all existing programs would benefit from extra speed. > > I am sending this mail by following rules from > https://wiki.php.net/rfc/howto . I don't have any knowledge of php > internals so unfortunatelly, I can't help with this. I at least hope > someone will take this RFC into consideration. > Independently of the question of whether we want to do this at all or not, there is a technical difficulty here: While most type checks are just that, scalar type checks (in particular in coercive mode) may perform type conversions. You pass "42" to a parameter accepting int and the parameter will become 42. Just disabling type checks completely would mean that the function now receives "42", which actively violates the type contract (even though the code was completely error free with enabled type checks). How do you propose to handle these cases? Nikita --00000000000059328f05711bed88--