|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69876 scalar typehint crash if default value is not related type
Submitted: 2015-06-18 15:47 UTC Modified: 2015-07-05 04:22 UTC
From: Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 7.0.0alpha1 OS: OSX & Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2015-06-18 15:47 UTC]
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:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-18 16:19 UTC]
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 20:04 UTC]
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-19 02:27 UTC]
-Status: Open +Status: Feedback
 [2015-06-19 02:27 UTC]
Please try using this snapshot:
For Windows:

 [2015-06-19 22:49 UTC]
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 for *NIX and 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

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
 [2015-06-22 09:12 UTC]
After laruence's feedback, I did a build from php7-alpha1, and got the same result. 

Then, I pulled php-src, and rebuild from scratch. The bug went away. 
I tried again on php7-alpha1, and not it is fine too, though builds were in different folders.

This was probably a build artefact. 

Note : I never could access
 [2015-07-05 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 03:05:53 2022 UTC