[php-src] Issue #13307: Constant as default value
| From: | SVGAnimate | Date: | Fri, 02 Feb 2024 14:59:33 +0000 |
| Subject: | [php-src] Issue #13307: Constant as default value | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246394@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13307
Author: SVGAnimate
### Description
The following code:
```php
<?php
function foo(int $p="1.1") {}
```
Resulted in this output:
```
Fatal error: Cannot use string as default value for parameter $p of type int
```
But not the following code:
```php
<?php
const default_value = "string";
function foo(int $p=default_value) {}
```
From there follows a series of different behaviors
<hr />
The following code:
```php
<?php
define('undefined', false);// or true : Bool
function foo(int $p=undefined) {
var_dump($p);
}
foo(1);
foo();
```
Resulted in this output:
```
int(1)
int(0)
```
<hr/>
The following code:
```php
<?php
define('undefined', 0.1);// Float
function foo(int $p=undefined) {
var_dump($p);
}
foo(1);
foo();
```
Resulted in this output:
```
int(1)
Deprecated: Implicit conversion from float 0.1 to int loses precision in /tmp/preview on line 4
int(0)
```
### PHP Version
PHP 8.3.2
### Operating System
Ubuntu 24.04