Bug #74750 [Opn->Nab]: strict_types not used for builtin callbacks (eg array_map)

From: Date: Fri, 28 May 2021 11:02:16 +0000
Subject: Bug #74750 [Opn->Nab]: strict_types not used for builtin callbacks (eg array_map)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234061@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74750&edit=1 ID: 74750 Updated by: cmb@php.net Reported by: fredemmott@php.net Summary: strict_types not used for builtin callbacks (eg array_map) -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem Operating System: Debian Jessie PHP Version: 7.1.6 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This is not particularly related to internal functions; rather whether strict_types apply depends on where a function is *called*[1]. Internal functions are practically defined in non strict_type files. If anybody feels this behavior should be changed, please pursue the RFC process[2]. [1] <https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict> [2] <https://wiki.php.net/rfc/howto> Previous Comments: ------------------------------------------------------------------------ [2017-07-09 00:33:57] gmblar+php at gmail dot com Same result in: <?php declare(strict_types=1); $input = [1, 2, 3]; array_map(function(string $foo) { var_dump($foo); }, $input); ?> > Isn't that to be expected? print_str() is called from array_map() > and the latter is not declared in a declare(strict_types=1) file. Does that mean that user defined functions are not affected by declare(strict_types=1), if they called by internal functions? // call_user_func respect strict_types call_user_func(function(string $foo) { var_dump($foo); }, $input); // array_filter ignores strict_types array_filter($input, function(string $foo) { var_dump($foo); }); ------------------------------------------------------------------------ [2017-06-13 12:36:51] spam2 at rhsoft dot net > Isn't that to be expected? print_str() is called from array_map() > and the latter is not declared in a declare(strict_types=1) file shouldn't it be logical that when *all* of your files start with declare(strict_types=1) everything has to use strict typing? ------------------------------------------------------------------------ [2017-06-13 11:53:46] cmb@php.net Isn't that to be expected? print_str() is called from array_map() and the latter is not declared in a declare(strict_types=1) file. ------------------------------------------------------------------------ [2017-06-12 16:32:09] fredemmott@php.net Description: ------------ In a strict file: - declare a function with typed parameters - call a builtin in a way that types don't match (eg if your function takes a string, array_map over ints) Test script: --------------- <?php declare(strict_types=1); function print_str(string $foo) { var_dump($foo); } $input = [1, 2, 3]; array_map('print_str', $input); Expected result: ---------------- Type error Actual result: -------------- Coercion ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74750&edit=1

« previous php.bugs (#234061) next »