Bug #69876 [Fbk]: scalar typehint crash if default value is not related type
| From: | kalle@php.net | Date: | Fri, 19 Jun 2015 22:49:54 +0000 |
| Subject: | Bug #69876 [Fbk]: scalar typehint crash if default value is not related type | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193708@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: kalle@php.net
Reported by: dams@php.net
Summary: scalar typehint crash if default value is not
related type
Status: Feedback
Type: Bug
Package: Reproducible crash
Operating System: OSX & Debian
PHP Version: 7.0.0alpha1
Block user comment: N
Private report: N
New Comment:
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php
for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php
for Win32
Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.
C:\dev\php-src>cat .git/refs/heads/master
89fda08473dd7df85b30cbdd7c9e6e1a1d516b90
C:\dev\php-src>php -v
PHP 7.0.0-dev (cli) (built: Jun 20 2015 00:43:44)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
C:\dev\php-src>php -r "function a(int $a = 1.2) {}"
Fatal error: Default value for parameters with a integer type hint can only be integer or NULL in
Command line code on line 1
Previous Comments:
------------------------------------------------------------------------
[2015-06-19 02:27:15] laruence@php.net
Please try using this snapshot:
http://snaps.php.net/php-trunk-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2015-06-18 20:04:48] cmb@php.net
I can't reproduce on Ubuntu (same rev: d9d1948) either. I get:
| Fatal error: Default value for parameters with a integer type
| hint can only be integer or NULL in %s on line %d
| Errors parsing %s
------------------------------------------------------------------------
[2015-06-18 16:19:46] cmb@php.net
Related to bug #69767 which is supposed to have been fixed. I
can't reproduce the issue on Windows with this very rev.
------------------------------------------------------------------------
[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