-
-
Notifications
You must be signed in to change notification settings - Fork 107
PHP 8 fix to avoid this warning: Undefined array key "input_value" #1103
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
PHP 8 fix to avoid this warning: Undefined array key "input_value" #1103
Conversation
Problem: $args[‘input_value’], min_value, max_value are not guaranteed to be assigned > PHP 8 throws notices. The added safeguards ensure that meaningful, complete, type-consistent values are always available - regardless of what Woo/plugins deliver - eliminating PHP 8 notices and keeping button states correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I'm in 👍
@Axos11 can you please double check?
|
The question is "why" is woocommerce loading that file in the checkout in the first place. Because in our templating we don't have any qty buttons on the checkout page. So basically I think both should be cleaned up (prevent loading, find out what actually loads the file in the first place) and the sanitation added as well. |
|
@Axos11 I'm new at woocommerce and I was just trying to build some custom discount functions with ACF while running in those warnings after pressing the checkout-button and it leads me into this file. So I was only trying to reach the checkout along this way. But yeah, the reason why should be good to know. |
|
@neralex every contribution is welcome and thanks for bringing the focus back to that issue. I think that I would not change any of the values without need but just escape early if the data needed for the logic isn't present. @crftwrk what do you think? add_filter('woocommerce_quantity_input_args', function (array $args) {
add_filter('woocommerce_quantity_input_type', 'change_quantity_input_type');
// Exit early if required args are not set
if (!isset($args['max_value']) || !isset($args['min_value']) || !isset($args['input_value'])) {
return $args;
}
// Rest of the code |
|
@Axos11 I think it's great because 1. it fixes the bug and 2. it changes the actual behaviour less invasively than my patch does. #shortandsimple |
|
I‘m in 👍 @neralex do you want to push a commit to this PR? |
|
Got it! |
Problem: $args[‘input_value’], min_value, max_value are not guaranteed to be assigned > PHP 8 throws notices.
Warning: Undefined array key "input_value" in \wp-content\themes\bootscore\woocommerce\inc\wc-qty-btn.php on line 31
The issue happens under php 8.3.2x while trying to reach the checkout.
The added safeguards ensure that meaningful, complete, type-consistent values are always available - regardless of what Woo/plugins deliver - eliminating PHP 8 notices and keeping button states correct.
It works for me. But please test the changes to see if the snippet still works for the cases you have added it for.