Skip to content

[BUG]: An empty argument after an option gives a PHP warning #66

Done

Description

@niden

Describe the bug

When the token after an option is an empty string, Parser::parse() gives a PHP warning. The parser reads the first character of the next token to check for a -. An empty string has no first character.

To Reproduce

use Phalcon\Cop\Parser;

$parser = new Parser();
$parser->parse(['app', '--name', '']);
$parser->parse(['app', '-n', '']);
Warning: Uninitialized string offset 0 in src/Parser.php on line 186
Warning: Uninitialized string offset 0 in src/Parser.php on line 203

The results are correct (['name' => ''] and ['n' => '']). But an application that converts warnings to exceptions stops with an error.

Expected behavior

The same results with no warning:

$parser->parse(['app', '--name', '']); // ['name' => '']
$parser->parse(['app', '-n', '']);     // ['n' => '']

Details

  • cli-options-parser: 2.0.0 and 3.0.x
  • PHP Version: 8.3 and later

Additional context

The look-ahead $argv[$i + 1][0] !== '-' is in two places in handleArguments(). !str_starts_with($argv[$i + 1], '-') gives the same result for a token that is not empty, and no warning for an empty token.

Activity

  1. added
    bug
    on Dec 4, 2026
  2. self-assigned this
    on Dec 4, 2026
  3. added theissue type on Dec 4, 2026
  4. added a commit that references this issue on Dec 4, 2026
  5. niden commented on Dec 4, 2026

    @niden
    SponsorMemberAuthor

    Resolved in #67

  6. moved this from Backlog to Implemented in Phalcon v5on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

  • Status
    Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions