Bug #72516 [NEW]: strict_types doesn't check the type sent to a callable
| From: | kinncj@php.net | Date: | Wed, 29 Jun 2016 16:59:01 +0000 |
| Subject: | Bug #72516 [NEW]: strict_types doesn't check the type sent to a callable | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-201912@lists.php.net to get a copy of this message | ||
From: kinncj
Operating system: CentOS Linux 7/x86_64
PHP version: 7.0Git-2016-06-29 (Git)
Package: *General Issues
Bug Type: Bug
Bug description:strict_types doesn't check the type sent to a callable
Description:
------------
when declared strict_types=1, the type check for a callable's parameter
is being bypassed.
Test script:
---------------
<?php
declare(strict_types=1);
class IntArray
{
public function __construct(array $initial = [])
{
array_walk($initial, function(int $value){}); // bypass
strict_types
foreach ($initial as $data) { $this->typeCheck($data); } // type
checked as expected
}
private function typeCheck(int $value)
{
}
}
$array = new IntArray(["12"]);
var_dump($array);
Expected result:
----------------
Fatal error: Uncaught TypeError: Argument 1 passed to {closure} must be
of the type integer, string given, called in /var/tmp/x.php on line 8
and defined in /var/tmp/x.php:12
Stack trace:
#0 /var/tmp/x.php(8): {closure('12')}
#1 /var/tmp/x.php(17): IntArray->__construct(Array)
#2 {main}
thrown in /var/tmp/x.php on line 12
Actual result:
--------------
Fatal error: Uncaught TypeError: Argument 1 passed to
IntArray::typeCheck() must be of the type integer, string given, called
in /var/tmp/x.php on line 9 and defined in /var/tmp/x.php:12
Stack trace:
#0 /var/tmp/x.php(9): IntArray->typeCheck('12')
#1 /var/tmp/x.php(17): IntArray->__construct(Array)
#2 {main}
thrown in /var/tmp/x.php on line 12
--
Edit bug report at https://bugs.php.net/bug.php?id=72516&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72516&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72516&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72516&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72516&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72516&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72516&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72516&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72516&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72516&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72516&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72516&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72516&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72516&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72516&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72516&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72516&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72516&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72516&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72516&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72516&r=mysqlcfg