Bug #69876 [NEW]: scalar typehint crash if default value is not related type

From: Date: Thu, 18 Jun 2015 15:47:12 +0000
Subject: Bug #69876 [NEW]: scalar typehint crash if default value is not related type
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193664@lists.php.net to get a copy of this message
From: dams Operating system: OSX & Debian PHP version: 7.0.0alpha1 Package: Reproducible crash Bug Type: Bug Bug description:scalar typehint crash if default value is not related type 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 bug report at https://bugs.php.net/bug.php?id=69876&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69876&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69876&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69876&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69876&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69876&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69876&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69876&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69876&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69876&r=support Expected behavior: https://bugs.php.net/fix.php?id=69876&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69876&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69876&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69876&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69876&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69876&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69876&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69876&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69876&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69876&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69876&r=mysqlcfg

« previous php.bugs (#193664) next »