Bug #69876 [Opn]: scalar typehint crash if default value is not related type
| From: | cmb@php.net | Date: | Thu, 18 Jun 2015 16:19:47 +0000 |
| Subject: | Bug #69876 [Opn]: scalar typehint crash if default value is not related type | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193665@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69876&edit=1
ID: 69876
Updated by: cmb@php.net
Reported by: dams@php.net
Summary: scalar typehint crash if default value is not
related type
Status: Open
Type: Bug
Package: Reproducible crash
Operating System: OSX & Debian
PHP Version: 7.0.0alpha1
Block user comment: N
Private report: N
New Comment:
Related to bug #69767 which is supposed to have been fixed. I
can't reproduce the issue on Windows with this very rev.
Previous Comments:
------------------------------------------------------------------------
[2015-06-18 15:47:12] dams@php.net
Description:
------------
With the new scalar typehint, when providing a default value with another type, PHP crashes.
function a(int $a = 1.2) {}
$a is supposed to be an integer, and the provided default value is a float.
I checked this on the last rev of php-src (d9d1948396285583a915018fe9310fad998876ca, Thu Jun 18
17:22:22 2015 +0200), both on Debian 8 and Osx 10.10
Test script:
---------------
<?php
function a(int $a = 1.2) {}
// sh: line 1: 49762 Segmentation fault: 11 php70 -l sth.php 2>&1
// Will also crash with the following :
/*
function a(int $a = true) {}
function a(int $a = "3") {}
function a(int $a = array()) {}
function a(string $a = 1.2) {}
function a(string $a = true) {}
function a(string $a = array()) {}
function a(string $a = 4) {}
function a(string $a = -1) {}
function a(float $a = true) {}
function a(float $a = "3") {}
function a(float $a = array()) {}
function a(float $a = 4) {}
function a(float $a = -1) {}
function a(bool $a = 1.2) {}
function a(bool $a = "3") {}
function a(bool $a = array()) {}
function a(bool $a = 4) {}
function a(bool $a = -1) {}
*/
?>
Expected result:
----------------
Don't crash.
Emit an error message at linting time to prevent such error.
Actual result:
--------------
=> sh: line 1: 49762 Segmentation fault: 11 php70 -l sth.php 2>&1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69876&edit=1