php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78648 Integer defaults are not cast to float for float properties
Submitted: 2019-10-08 13:32 UTC Modified: 2019-10-08 13:34 UTC
From: andreas dot bittner at aracom dot de Assigned: nikic (profile)
Status: Closed Package: Class/Object related
PHP Version: 7.4.0RC3 OS: Docker 7.4.0RC3-apache
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andreas dot bittner at aracom dot de
New email:
PHP Version: OS:

 

 [2019-10-08 13:32 UTC] andreas dot bittner at aracom dot de
Description:
------------
A float property that is defaulted to an integer has the type integer instead of float. I would expect the default integer to be cast to float when assigned to a float type property.

Please see provided test script for an example.

Test script:
---------------
<?php

echo 'PHP Version: ' . PHP_VERSION;

class Foo {
    public float $baa = 1;
}

$instance = new Foo();
echo "\n\nbefore assign\n";
var_dump($instance->baa);
var_dump(gettype($instance->baa));
$instance->baa = 1;

echo "\n\nafter assign\n";
var_dump($instance->baa);
var_dump(gettype($instance->baa));

Expected result:
----------------
PHP Version: 7.4.0RC3

before assign
float(1)
string(6) "double"


after assign
float(1)
string(6) "double"


Actual result:
--------------
PHP Version: 7.4.0RC3

before assign
int(1)
string(7) "integer"


after assign
float(1)
string(6) "double"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-08 13:34 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-10-08 13:44 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9004102b99be4d3811d69ad61149dc2959579e0a
Log: Fixed bug #78648
 [2019-10-08 13:44 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-10-08 13:52 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9004102b99be4d3811d69ad61149dc2959579e0a
Log: Fixed bug #78648
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 16:01:30 2024 UTC