HD Quiz Styler 1.4.1 collapses quizzes on PHP 8 (loose comparisons with “” in fields.php)
Hello,
after upgrading our site from PHP 7.4 to PHP 8.3, all HD Quiz quizzes styled with HD Quiz Styler 1.4.1 render collapsed: the quiz has 0 width and the answer text has 0px font size.
Cause
Unset numeric settings are stored as integer 0 in the hdq_styler_options option, for example:
maximum_quiz_width => [‘value’ => 0, ‘type’ => ‘integer’]
answer_font_size => [‘value’ => 0, ‘type’ => ‘integer’]
question_padding => [‘value’ => 0, ‘type’ => ‘integer’]
hdfields/classes/fields.php uses loose comparisons with an empty string to detect unset values:
line 75 (get_values()): if (isset($this->flat_values[$k]) && $value != “”)
line 278 (get_value()): if ($value == “”)
On PHP 7.4, 0 == “” is true, so these zeros were treated as “not set” and HD Quiz’s defaults applied. Since PHP 8.0 (RFC “Saner string to number comparisons”), 0 == “” is false. The saved zeros therefore override the defaults, and the styler outputs:
–hdq-maximum-quiz-width: 0%;
–hdq-answer-font-size: 0px;
–hdq-question-title-size: 0px;
–hdq-question-padding: 0px;
–hdq-question-spacing: 0px;
Verified
PHP 7.4.25: var_export(0 == “”) → true
PHP 8.3.16: var_export(0 == “”) → false
Local workaround (restores the PHP 7 behavior):
line 75: if (isset($this->flat_values[$k]) && !($value === “” || $value === null || $value === false || $value === 0 || $value === 0.0)) {
line 278: if ($value === “” || $value === null || $value === false || $value === 0 || $value === 0.0) {
With both changes, quizzes render correctly again on PHP 8.3. Could you include a fix in a future release, so our patch isn’t overwritten by plugin updates? The bundled HDFields library may have other loose == “” comparisons, for example in sanitize.php intval() / floatval() / currency().
Environment: WordPress 6.8, PHP 8.3.16, HD Quiz 2.2.3, HD Quiz Styler 1.4.1.
Thank you!
Hi Jiri,
good news! This has already been fixed as is ready for the next release (new HDFields already in both Save Results Pro as well as the main HD Quiz itself). If all goes well it will be up tomorrow. I’ll notify you here to confirm once it’s live
Hello, awesome, thanks for letting me know 🙂
New version is out. You can either wait for your site to check for the update, or manually update from your account page https://hdplugins.com/account/
Tons of new features and settings, a better live preview, new default themes to choose from, plus much more 🙂
Hello, thank you, but after the update to new version, the issue is back and the CSS styles are totally broken. Exactly this happened after we updated to PHP8.
With our manual fix, which I posted above, CSS styles works great, as you can see on this screenshot. But after the upgrade to v1.5 CSS styles are back and totally broken 🙁 So I reverted back to v 1.4.1 with our manual fix, which works great under PHP8, as you can see on our live site here for example.
Hi Jiri,
this version was fully tested on PHP 8.3 and 8.5. All tests passed, so I am confident that there is not a PHP8 issue. (this site uses PHP 8.5)
Instead, your issue stems from 1 of 2 things.
The first thing to check for is a browser or site cache. I see you are also using Cloudflare so make sure you clear that cache as well as they will cache CSS and JS files.
If that doesn’t work (and to be honest, I doubt that is the issue) then that means the that actual issue is your saved data.
If you, for example, have a literal 0 saved in one of the settings, then that is what will render. Your previous fix/patch avoids this by treating all 0s as if they were blank. If I added that patch to the plugin directly, it would then break it for users who actually DO want to use a 0 value.
Your AI agent called this out directly in your original post
Unset numeric settings are stored as integer 0 in the hdq_styler_options option, for example:
maximum_quiz_width => [‘value’ => 0, ‘type’ => ‘integer’]
answer_font_size => [‘value’ => 0, ‘type’ => ‘integer’]
question_padding => [‘value’ => 0, ‘type’ => ‘integer’]That is your agent telling you that the actual settings are saved as 0.
If the saved data is the issue for you then you have two courses of action.
1) Reset the settings. Hit the reset button next to the save button to delete all saved settings for the addon. You can then reconfigure again without the bad data.
2) if you made a lot of changes and don’t want to do that, then good news! The new v1.5 has an import/export tool for settings. If you export your settings, you can upload it somewhere like file.io and I can quickly clean it for you.