Skip to content

Conversation

@pmo2band
Copy link

…ing them, preventing potential undefined index errors.

tumbled over this while installing Google Ads Client https://github.com/googleads/google-ads-php
but using getOpt 4.0,4 insted of 3.4 (due to PHP 8.3)

…ing them, preventing potential undefined index errors.
Copilot AI review requested due to automatic review settings October 29, 2025 13:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds defensive isset() checks before accessing optional array elements at indices 3 and 4 in the parseArray() method to prevent potential undefined index errors.

  • Added isset($array[3]) check before accessing the description element
  • Added isset($array[4]) check before accessing the default value element
Comments suppressed due to low confidence (1)

src/OptionParser.php:74

  • The $rowSize variable is calculated before potentially modifying $array on line 73. When $rowSize < 3, the array is replaced with a 3-element array from completeOptionArray(), but $rowSize retains the original count. This creates a logical inconsistency where lines 78 and 82 check $rowSize >= 4 and $rowSize >= 5 but $array may only have 3 elements. Consider recalculating $rowSize after line 73: $rowSize = count($array);
        $rowSize = count($array);
        if ($rowSize < 3) {
            $array = self::completeOptionArray($array);
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tflori
Copy link
Member

tflori commented Nov 2, 2025

Oh wow, didn't know google is using this lib 🙂

So google is using it wrong or is that a regression? Something that worked in 3.x does not work in 4.0?

Can you maybe create a Test to demonstrate what got fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants