PHP8 Fix
-
Updating from PHP7.4 to PHP8 and beyond gives the following error:
Fatal error: Uncaught TypeError: Unsupported operand types: string / string in /wp-content/plugins/wp-video-lightbox/misc_functions.php:114Here is the proposed fix:
The error message
Unsupported operand types: string / string
at the line$aspect_ratio = $height/$width;
implies that the operation is attempting to divide two string values, which is not a valid operation in PHP.In the context of your
wp_vid_lightbox_youtube_handler
function, the$width
and$height
variables are being assigned values from an associative array ($atts
), which are initially being passed as strings. In PHP, you cannot perform mathematical operations on strings directly without converting them to numbers.To fix this error, you can convert these string values to integers or floats before the division operation. Here’s how you can do this:
Change this line:
phpCopy code
$aspect_ratio = $height/$width;
to:
phpCopy code
$aspect_ratio = (float)$height / (float)$width;
The
(float)
before$height
and$width
casts these variables to float numbers before the division operation is performed. This should help you eliminate the fatal error. However, you should ensure that your width and height parameters are always numeric and not zero to avoid division by zero errors.
- The topic ‘PHP8 Fix’ is closed to new replies.