Bug #74750 [Com]: strict_types not used for builtin callbacks (eg array_map)

From: Date: Sun, 09 Jul 2017 00:33:58 +0000
Subject: Bug #74750 [Com]: strict_types not used for builtin callbacks (eg array_map)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209929@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 Comment by: gmblar+php at gmail dot com Reported by: fredemmott@php.net Summary: strict_types not used for builtin callbacks (eg array_map) Status: Open Type: Bug Package: Scripting Engine problem Operating System: Debian Jessie PHP Version: 7.1.6 Block user comment: N Private report: N New Comment: 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); }); Previous Comments: ------------------------------------------------------------------------ [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 (#209929) next »