Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing objects to round() as of PHP8 not getting detected #1585

Open
hchonov opened this issue Jul 20, 2023 · 1 comment
Open

Passing objects to round() as of PHP8 not getting detected #1585

hchonov opened this issue Jul 20, 2023 · 1 comment
Labels

Comments

@hchonov
Copy link

hchonov commented Jul 20, 2023

Bug Description

Since PHP8 the num parameter of the round() function no longer accepts internal objects which support numeric conversion. In our case we were passing an object of type SimpleXMLElement to round() which was not detected by the rules for PHP 8 comparability.

Given the following reproduction Scenario

The following code that used to pass SimpleXMLElement to round() was not detected as false in our case:

$svg_xml = simplexml_load_file($image_path);
$width = $svg_xml->attributes()->width;
round($width);

which was then throwing an Error:

TypeError: round(): Argument #1 ($num) must be of type int|float,

This could've been detected though since the ::attributes() returns an SimpleXMLElement object with attributes that are also of the same type.

@jrfnl
Copy link
Member

jrfnl commented Jul 20, 2023

@hchonov This is not typically the type of check which PHPCompatibility is suitable to detect. PHPCompatibility does not have access to the runtime value of variable, so also doesn't have access to the type.

attributes() can return SimpleXMLElement or null, the width attribute (property) may or may not exist and can be of any XML supported types (can't be determined by examining the code).

In general, if a check would more often than not lead to a false positive, it is not suitable for PHPCompatibility and IMO, this is one of those cases.

@jrfnl jrfnl added the wontfix label Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants