Bug #72248 [Com]: Optimization erroneously enforces strict types in call_user_func

From: Date: Tue, 20 Sep 2016 08:41:42 +0000
Subject: Bug #72248 [Com]: Optimization erroneously enforces strict types in call_user_func
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204144@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72248&edit=1 ID: 72248 Comment by: sam at mousa dot nl Reported by: bwoebi@php.net Summary: Optimization erroneously enforces strict types in call_user_func Status: Open Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 7.0.6 Block user comment: N Private report: N New Comment: This does not only apply to PHP internal functions, this code has the same behavior: Test scripts: <?php declare(strict_types=1); namespace a; var_dump( call_user_func(function(string $test) { return $test; }, 5) ); <?php declare(strict_types=1); var_dump( call_user_func(function(string $test) { return $test; }, 5) ); However in this scenario the desired behavior is different. Since we have strict types on user code I assume we would always want an error, even in namespaces. Previous Comments: ------------------------------------------------------------------------ [2016-05-20 13:47:38] bwoebi@php.net Description: ------------ Due to our call_user_func() optimizations (which by the way also removes the additional internal stack frame in the stacktrace...; which ultimately causes the misbehavior), call_user_func[_array]() calls apply, when optimized, the strict_type mode of the caller, which they shouldn't. In general, PHP functions count internally as weakly typed and this behavior shall be always the same. Test script: --------------- // first script (works as expected, with namespace) <?php declare(strict_types=1); namespace a; var_dump(call_user_func("strlen", 1));' // second script (bad behavior, without namespace) <?php declare(strict_types=1); var_dump(call_user_func("strlen", 1));' Expected result: ---------------- // first script int(1) // second script int(1) Actual result: -------------- // first script int(1) // second script Fatal error: Uncaught TypeError: strlen() expects parameter 1 to be string, integer given in Command line code:1 Stack trace: #0 Command line code(1): strlen(1) #1 {main} thrown in Command line code on line 1 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72248&edit=1

« previous php.bugs (#204144) next »