Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120969 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25468 invoked from network); 1 Sep 2023 18:09:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Sep 2023 18:09:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DB77C1804C6 for ; Fri, 1 Sep 2023 11:09:15 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 1 Sep 2023 11:09:15 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-31977ace1c8so1967082f8f.1 for ; Fri, 01 Sep 2023 11:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693591754; x=1694196554; darn=lists.php.net; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=C8kyy7zKJnnZB4e27Ymv33R//zq7fL1GQOpb8EWdq/E=; b=VE1xKP4CVwzPOUUFYrxqp+M9OlXzYRJCkq4gOrA08VBx1S5xbjTR0tJC9we+ySD+Ku sb4OIvjqlCbqkR2H1OjMWmTtpH92ZLNeHhWmPk3Q6P2bWjzc/GsobmzLdOZqZnIYJoy3 lAWfLQ7QNQCAUVvliD7Q1MeQXzgW23GxjRUe5yo32upDdfxhON0I+dSWtBN1FeJpxMFj 2ZgBt5+qNm5DAZY6jGhxB3FplakZiZqJO65dJnrgaW9zHY9raET+ODRcptcEtgLbWV4c T1RFPtJGSNf7/AktkC8QEQs2tXtgZ5gvuWQBXVC6qR6GU+DWMBECr8yQCsxTRzGfQdFl bNww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693591754; x=1694196554; h=in-reply-to:from:content-language:references:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=C8kyy7zKJnnZB4e27Ymv33R//zq7fL1GQOpb8EWdq/E=; b=J2Kv1QEaPdMTo7LKDai2SetHsWkgJ0QUS7MIgePCHYgePbiWfgf9o6AyvHE5u1a44E 4ah6Pj9tjPLfId6k43Uj41zOstejLrLzPMTEeEEBAX+4m64971pUZy0/2Q6kj/zeq4im N9ib79nuom9P0StRzBrwaSxpOtcvgY0Aqc9nkDQ1230WJD36zPWLEetjlhxlBdNYHM0P D2H7E6zkVpXicG922But2fo1OA97Oa075j6vaB4RfCLuQ5yKfgFjN5keTzkvXJv85vbr fJl1JqS4JoZwNCmsDALtt1BngMHVIU0unkAAD6X2DUoQapCsouvgF4dNOjhga8CcWV9C pvTw== X-Gm-Message-State: AOJu0Yxzx3NWjYWOGGyOuI+hHlo4iKuJTtA7eQdv7FYNTwUrr6yYVwBH m2n5Gl5bhFYp3xa4M1D5JGYTzPxW13w= X-Google-Smtp-Source: AGHT+IHKyrhwuwBPaO0g7ohzqVl9u+HNSdoAiJcWLSNfWLH3noGQqcighvC6o1CoOkkQh0wCa24gsg== X-Received: by 2002:a05:6000:10:b0:319:8261:2087 with SMTP id h16-20020a056000001000b0031982612087mr2333047wrx.43.1693591753357; Fri, 01 Sep 2023 11:09:13 -0700 (PDT) Received: from [192.168.0.22] (cpc83311-brig21-2-0-cust191.3-3.cable.virginm.net. [86.20.40.192]) by smtp.googlemail.com with ESMTPSA id p15-20020a5d68cf000000b0031416362e23sm5958801wrw.3.2023.09.01.11.09.11 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Sep 2023 11:09:12 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------FUntaCn7Gg9YFJKuuT4bzONs" Message-ID: <5075145d-dcbc-a993-9394-665fbb6fd747@gmail.com> Date: Fri, 1 Sep 2023 19:09:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 To: internals@lists.php.net References: <4406C50C-18FF-4F20-BA7B-206E86610CCC@sakiot.com> Content-Language: en-GB In-Reply-To: <4406C50C-18FF-4F20-BA7B-206E86610CCC@sakiot.com> Subject: Re: [PHP-DEV] Apply strict_types to internal functions From: rowan.collins@gmail.com (Rowan Tommins) --------------FUntaCn7Gg9YFJKuuT4bzONs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 29/08/2023 01:46, Saki Takamachi wrote: > As the documentation below states, PHP's internal functions currently ignore strict_types. > https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict Just to be really clear, it is not true that internal functions "ignore" the setting; they behave exactly the same as any userland function which was *declared* in strict_types=0 mode. The warning in the manual is actually a consequence of the following Note (perhaps the order should be reversed?): 1. Strict typing applies to function calls made from within the file with strict typing enabled 2. Function calls from within internal functions will not be affected by the |strict_types| declaration To clarify the scenario, imagine three files: /* a.php */ declare(strict_types=0); function call_me_back(callable $f, mixed $input) {     $f($input); } /* b.php */ declare(strict_types=1); function output_me(string $output) {     echo "$output\n"; } /* c.php */ declare(strict_types=1); call_me_back( output_me(...), 42 ); The only calls that happen are: 1. A call from c.php to call_me_back; c.php is in strict_types=1 mode, so the parameters $f and $input will not be coerced 2. A call from a.php to output_me; a.php is in strict_types=0 mode, so the parameter $output *will* be coerced to a string The behaviour of internal functions like array_filter is exactly the same - array_filter is  the caller, and it is defined in strict_types=0 mode, just like call_me_back above; the mode set in any other code is irrelevant, because it is not the caller. As Claude Pache, it's actually very difficult to design a version of the feature that would be fully intuitive in this case - if I write the below, does the caller of wrapped_array_filter still get to control the mode that call_me_back is run under? function call_me_back(int $value) {     return $value <= 42; } function backwards_array_filter(array $array, ?callable $callback = null, int $mode = 0): array {     return array_reverse(   array_filter($array, $callback, $mode)   ); } // In another file: var_dump( backwards_array_filter($some_array, call_me_back(...)) ); Regards, -- Rowan Tommins [IMSoP] --------------FUntaCn7Gg9YFJKuuT4bzONs--