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 when switching to PHP 8 #8025

Closed
tyssen opened this issue Jun 8, 2021 · 3 comments
Labels

Comments

@tyssen
Copy link

tyssen commented Jun 8, 2021

Description

The following code works fine if I'm using PHP 7.4, but if I change it to 8, I get

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

{% set thumbTransform = {
    mode: 'fit',
    height: height | default,
    width: width | default,
    quality: quality | default('90')
}%}

{{ entry.entryImage.one().url(thumbTransform) }}

If I comment out {{ entry.entryImage.one().url(thumbTransform) }}, the error goes away.

Additional info

  • Craft version: 3.6.16
  • PHP version: 8
  • Database driver & version: MySQL 5.7.28

Stack trace

TypeError: round(): Argument #1 ($num) must be of type int|float, string given in /app/vendor/craftcms/> cms/src/elements/Asset.php:1191
> Stack trace:
> #0 /app/vendor/craftcms/cms/src/elements/Asset.php(1191): round('')
#1 /app/vendor/twig/twig/src/Extension/CoreExtension.php(1511): craft\elements\Asset->getUrl(Array)
#2 /app/vendor/craftcms/cms/src/helpers/Template.php(106): twig_get_attribute(Object> (craft\web\twig\Environment), Object(Twig\Source), Object(craft\elements\Asset), 'url', Array, 'method', false, false)
#3 /app/storage/runtime/compiled_templates/40/40d31c23964b62e8731bd705a524025b7c6aa884475f423dc744795bb469b6a2.php(135): > craft\helpers\Template::attribute(Object(craft\web\twig\Environment), Object(Twig\Source), Object(craft\elements\Asset), 'url', Array, 'method')
> #4 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_ee03ea67fd269cc1d8f581a8bb6bd529d44b28c269658c422dbd84823261593c->doDisplay(Array, Array)
#5 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
> #6 /app/storage/runtime/compiled_templates/86/86a8206fd188248f4b0e943d3f6adec2dc4adf1e9ba30ee58077cd9acbaa654d.php(404): Twig\Template->display(Array)
> #7 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_33546a4b7a03781c683dab59c2c463676e2fdf649ab5ddb859f4bf697cef7ea8->doDisplay(Array, Array)
#8 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
> #9 /app/storage/runtime/compiled_templates/ad/ad62434820b86d8cecc23c82617c72f818103c112b3781d8617005d65132da9b.php(55): Twig\Template->display(Array)
> #10 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_cea3a15643600ca3cbb50a6d58f6b41d2c6a1bb5025677de8204c373991b1035->doDisplay(Array, Array)
#11 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#12 /app/storage/runtime/compiled_templates/2e/> 2eec3b809d72796f5eb2b2dc052fd3784f9e077e008ac8b0dc08dac488b2ed5d.php(62): Twig\Template->display(Array, Array)
> #13 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_4ee3aa1bb6c67c4e7786140d00998de6d577f9ed9841086ebce2c7b68787820d->doDisplay(Array, Array)
#14 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
#15 /app/storage/runtime/compiled_templates/46/> 46b807ed23de890b969d3002d64c937b4a7b5fd1e7020ad5263a522d3d7c1ba4.php(89): Twig\Template->display(Array, Array)
> #16 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_870536f3cfec5f05e322e22480de52379d3868d0fe2c065937f35cb7c5b7cea2->doDisplay(Array, Array)
#17 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
> #18 /app/storage/runtime/compiled_templates/e4/e41ddcac926aed0659f9171a357099ebb44a66d74517275ac7dfbf7f74fd8e1a.php(38): Twig\Template->display(Array)
> #19 /app/vendor/twig/twig/src/Template.php(405): > __TwigTemplate_51d04c9c73e04fc6ff7c64cdc625bd34e83b78ba5df34ef213fe7864a5400b31->doDisplay(Array, Array)
> #20 /app/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling(Array, Array)
> #21 /app/vendor/twig/twig/src/Template.php(390): Twig\Template->display(Array)
> #22 /app/vendor/twig/twig/src/TemplateWrapper.php(45): Twig\Template->render(Array, Array)
> #23 /app/vendor/twig/twig/src/Environment.php(318): Twig\TemplateWrapper->render(Array)
#24 /app/vendor/craftcms/cms/src/web/View.php(389): Twig\Environment->render('_helpers/entryH...', Array)
> #25 /app/vendor/craftcms/cms/src/web/View.php(450): craft\web\View->renderTemplate('_helpers/entryH...', Array)
> #26 /app/vendor/craftcms/cms/src/web/Controller.php(257): craft\web\View->renderPageTemplate('_helpers/entryH...', Array, 'site')
> #27 /app/vendor/craftcms/cms/src/controllers/TemplatesController.php(100): > craft\web\Controller->renderTemplate('_helpers/entryH...', Array)
> #28 [internal function]: craft\controllers\TemplatesController->actionRender('_helpers/entryH...', Array)
> #29 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
> #30 /app/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)
> #31 /app/vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction('render', Array)
#32 /app/vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction('render', Array)
> #33 /app/vendor/craftcms/cms/src/web/Application.php(278): yii\base\Module->runAction('templates/rende...', Array)
> #34 /app/vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction('templates/rende...', Array)
> #35 /app/vendor/craftcms/cms/src/web/Application.php(263): yii\web\Application->handleRequest(Object(craft\web\Request))
> #36 /app/vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest(Object> (craft\web\Request))
> #37 /app/web/index.php(21): yii\base\Application->run()
#38 {main}
@tyssen tyssen added the bug label Jun 8, 2021
@andris-sevcenko
Copy link
Contributor

Looking at the stack trace, it would imply that you're passing an empty string as the width for the Asset.

Granted, Craft should be normalizing that to a 0.00 value, but thought you should be aware of it.

@tyssen
Copy link
Author

tyssen commented Jun 8, 2021

Thanks. Changing it to width: width | default(0) fixed it.

@andris-sevcenko
Copy link
Contributor

No problem - I made it more defensive on our end, too!

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