qTranslate-XT (eXTended) - reviving qTranslate-X multilingual plugin for WordPress. A new community-driven plugin soon. Built-in modules for WooCommerce, ACF, slugs and others.
GNU General Public License v2.0
545
stars
103
forks
source link
Optional arguments are sometimes missing `?` in the type. #1393
qtranxf_convertURL causes a fatal error if invoked with a $url of null
To Reproduce
Steps to reproduce the behavior:
Put this in your functions.php:
qtranxf_convertURL(null, 'en');
Reload the site
Expected behavior
I'd expect no error
Proposed Fix
In PHP >= 8, optional arguments need to be typed using ?string, ?bool and so forth. So we should change qtranxf_convertURL (and many other functions in qtranslate-xt) from this:
The code you provided would be invalid because you are trying to assign null as the default value to an argument with a non-nullable type (string). If you want the $url to be able to accept null, you should use the ? character before the type.
Debug info
Go to <YOUR_SITE>/wp-admin/options-general.php?page=qtranslate-xt#troubleshooting.
Press Collect information button and copy/paste the output below.
Describe the bug
qtranxf_convertURL
causes a fatal error if invoked with a$url
ofnull
To Reproduce Steps to reproduce the behavior:
functions.php
:Expected behavior I'd expect no error
Proposed Fix In PHP >= 8, optional arguments need to be typed using
?string
,?bool
and so forth. So we should changeqtranxf_convertURL
(and many other functions in qtranslate-xt) from this:...to this:
ChatGPT can explain the issue much clearer:
Debug info Go to
<YOUR_SITE>/wp-admin/options-general.php?page=qtranslate-xt#troubleshooting
. PressCollect information
button and copy/paste the output below.Additional context
Here's the stack trace where I originally encountered the error. It seems to be related with Yoast SEO somehow.