|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-06-12 16:32 UTC] 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
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 16:00:01 2025 UTC |
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); });