Title: PHP 8.0 &#8211; Undefined variable $viewbox_width
Last modified: April 14, 2022

---

# PHP 8.0 – Undefined variable $viewbox_width

 *  Resolved [jinsley8](https://wordpress.org/support/users/jinsley8/)
 * (@jinsley8)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-undefined-variable-viewbox_width/)
 * Hi,
 * I’m testing updating a server to PHP 8.0 and on the frontend pages I’m getting
   the following PHP Warnings now.
 * Undefined variable $viewbox_width – wp-content/plugins/safe-svg/safe-svg.php:
   507
    Undefined variable $viewbox_height – wp-content/plugins/safe-svg/safe-svg.
   php:508
 * 15 warnings for each one – how to I correct this?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [jinsley8](https://wordpress.org/support/users/jinsley8/)
 * (@jinsley8)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-undefined-variable-viewbox_width/#post-15560112)
 * Actually, I just noticed if I switch back to PHP 7.4 it changes to PHP notice,
   not warning.
 * How can we fix this?
 *  [Armands](https://wordpress.org/support/users/armandsdz/)
 * (@armandsdz)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-undefined-variable-viewbox_width/#post-15564595)
 * Version 2.0.0 introduced some changed to fix of width/height of the SVGs.
    But
   the introduced part could be improved. Now it’s forcing to use dimensions found
   in Viewbox even if they are not found at all i.e. SVG file is not having viewbox.
   In that scenario variables $viewbox_width/$viewbox_height are not set but despite
   that code in safe-svg.php:507,508 uses those variables to set width/height of
   SVG.
 * In my case that resulted in SVGs being output as 100x100px (kind of default fallback)
   despite them having explicit width/height set because that file didn’t have Viewbox
   set at all.
 * Yes, I can use the new filter “safe_svg_use_width_height_attributes” but that
   seems to be more like a temporary workaround.
 * Code logic in this place should be improved to check if there are actually viewbox
   values to set before using them.
 *  Plugin Contributor [Jeffrey Paul](https://wordpress.org/support/users/jeffpaul/)
 * (@jeffpaul)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-undefined-variable-viewbox_width/#post-15576336)
 * Note that v2.0.1 was just released, would be curious if you’re all still experiencing
   issues or not… thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘PHP 8.0 – Undefined variable $viewbox_width’ is closed to new replies.

 * ![](https://ps.w.org/safe-svg/assets/icon.svg?rev=2779013)
 * [Safe SVG](https://wordpress.org/plugins/safe-svg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/safe-svg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/safe-svg/)
 * [Active Topics](https://wordpress.org/support/plugin/safe-svg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/safe-svg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/safe-svg/reviews/)

 * 3 replies
 * 3 participants
 * Last reply from: [Jeffrey Paul](https://wordpress.org/support/users/jeffpaul/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/php-8-0-undefined-variable-viewbox_width/#post-15576336)
 * Status: resolved