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

round(): Argument #1 ($num) must be of type int|float, string given error #757

Closed
mnarbash opened this issue Jan 9, 2021 · 17 comments
Closed
Labels

Comments

@mnarbash
Copy link

mnarbash commented Jan 9, 2021

When I try download pdf after render like this:

    $pdf = PDF::loadView('storeapis::pdfStore', ['products' => $products, 'store' => $store, 'image' => $image]);

    return $pdf->download('products.pdf');

PHP 8 and Laravel 8
error:
"message": "round(): Argument #1 ($num) must be of type int|float, string given",
"exception": "TypeError",
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Style.php",
"line": 3321,
"trace": [
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Style.php",
"line": 3321,
"function": "round"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Style.php",
"line": 894,
"function": "set_z_index",
"class": "Dompdf\Css\Style",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Stylesheet.php",
"line": 1638,
"function": "__set",
"class": "Dompdf\Css\Style",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Stylesheet.php",
"line": 1671,
"function": "_parse_properties",
"class": "Dompdf\Css\Stylesheet",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Stylesheet.php",
"line": 1415,
"function": "_parse_sections",
"class": "Dompdf\Css\Stylesheet",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Css/Stylesheet.php",
"line": 420,
"function": "_parse_css",
"class": "Dompdf\Css\Stylesheet",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Dompdf.php",
"line": 649,
"function": "load_css_file",
"class": "Dompdf\Css\Stylesheet",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/dompdf/dompdf/src/Dompdf.php",
"line": 761,
"function": "processHtml",
"class": "Dompdf\Dompdf",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/barryvdh/laravel-dompdf/src/PDF.php",
"line": 208,
"function": "render",
"class": "Dompdf\Dompdf",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/barryvdh/laravel-dompdf/src/PDF.php",
"line": 155,
"function": "render",
"class": "Barryvdh\DomPDF\PDF",
"type": "->"
},
{
"file": "/Users/nizaralmohammad/Sites/tree-with-layout/vendor/barryvdh/laravel-dompdf/src/PDF.php",
"line": 178,
"function": "output",
"class": "Barryvdh\DomPDF\PDF",
"type": "->"
},

@socieboy
Copy link

I have the same problem. any fix on that?

@asbrito
Copy link

asbrito commented Jan 14, 2021

I also have the same problem.

@webissupport
Copy link

webissupport commented Jan 22, 2021

This might not be ideal but this is working and did not came across any side issues yet: on line 3321 of the Style.php script cast the $val variable to integer: round((int)$val)

@lenomosh
Copy link

On Style.php on line 3321
change round($val) to round((int)$val)
In my case it was on line 3304
So it is better to find the following statement

        if (round($val) != $val && $val !== "auto") {
            return;
        }

and change it to

        if (round((int)$val) != $val && $val !== "auto") {
            return;
        }

@nursandiid
Copy link

please, check your php version.
I also have the same problem if I use php v.8 , but after I swicth to version 7 the problem was resolved

@JuanDeLeon
Copy link

JuanDeLeon commented Mar 4, 2021

Fixed for me after upgrading to 0.9.0
This was my composer update log:

  • Downloading dompdf/dompdf (v1.0.2)
  • Downloading barryvdh/laravel-dompdf (v0.9.0)
  • Upgrading dompdf/dompdf (v0.8.6 => v1.0.2): Extracting archive
  • Upgrading barryvdh/laravel-dompdf (v0.8.7 => v0.9.0): Extracting archive

@stale
Copy link

stale bot commented Jun 1, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf.
If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

@stale stale bot added the stale label Jun 1, 2021
@carletonm
Copy link

This seems to be an issue that occurs with php 8. They need to fix the style.php file and change round($val) to round((int)$val). As lenomosh said.

@stale stale bot removed the stale label Jun 2, 2021
@aromka
Copy link

aromka commented Jul 21, 2021

Also occurs with PHP 7 if you use strict types. Is there an update on this?

@charliedearce
Copy link

its working on php v7.4.22

@stale
Copy link

stale bot commented Oct 2, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf.
If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

@stale stale bot added the stale label Oct 2, 2021
@stale stale bot closed this as completed Oct 12, 2021
@shakethatweight-simon
Copy link

This has been fixed in dompdf with a better solution than the ones posted above.

Can you confirm when the fixed version will be included in Wordpress.

dompdf/dompdf#2670

@nizigama
Copy link

nizigama commented Mar 28, 2022

On Style.php on line 3321 change round($val) to round((int)$val) In my case it was on line 3304 So it is better to find the following statement

        if (round($val) != $val && $val !== "auto") {
            return;
        }

and change it to

        if (round((int)$val) != $val && $val !== "auto") {
            return;
        }

NEVER EVER CHANGE VENDOR FILES EVER!!!!!!!!!!!!!!!!!!!!!!!!
This is a type error, in short it means your current php version doesn't match with the one required by the package.Just change the dompdf package to a version that matches your php version

@agitnaeta
Copy link

I still have issue here,
using php 8.0
apache 2.4.53
"laravel/framework": "^8.12",
"barryvdh/laravel-dompdf": "^0.8.7",

@nizigama
Copy link

I still have issue here, using php 8.0 apache 2.4.53 "laravel/framework": "^8.12", "barryvdh/laravel-dompdf": "^0.8.7",

What issue? can you explain more about your issue

@saleh-khalaf
Copy link

i have same issue with php7.4 and doing if (round((int)$val) != $val && $val !== "auto") { return; } fixed the issue but shows a unorganized pdf

@saleh-khalaf
Copy link

i have same issue with php7.4 and doing if (round((int)$val) != $val && $val !== "auto") { return; } fixed the issue but shows a unorganized pdf

i reinstall php7.4 and now all working fine

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