coduo/php-matcher

Fatal error on version 3.0: Argument 1 passed to Parser::unexpectedSyntaxError() must be of the type array, null given

emodric opened this issue · 6 comments

Hi, I'm using PHP Matcher 3.0 on PHP 7.2.

The following script:

<?php

require 'vendor/autoload.php';

use Coduo\PHPMatcher\Factory\SimpleFactory;

$matcher = (new SimpleFactory)->createMatcher();

$a = '{"foo": "","bar": "baz"}';
$b = '{"foo": "","bar": "bazz"}';

$match = $matcher->match($a, $b);

results in the following exception:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Coduo\PHPMatcher\Parser::unexpectedSyntaxError() must be of the type array, null given, called in vendor/coduo/php-matcher/src/Parser.php on line 62 and defined in vendor/coduo/php-matcher/src/Parser.php:248
Stack trace:
#0 vendor/coduo/php-matcher/src/Parser.php(62): Coduo\PHPMatcher\Parser->unexpectedSyntaxError(NULL, '@type@ pattern')
#1 vendor/coduo/php-matcher/src/Parser.php(50): Coduo\PHPMatcher\Parser->getPattern()
#2 vendor/coduo/php-matcher/src/Parser.php(29): Coduo\PHPMatcher\Parser->getAST('')
#3 vendor/coduo/php-matcher/src/Matcher/StringMatcher.php(43): Coduo\PHPMatcher\Parser->hasValidSyntax('')
#4 vendor/coduo/php-matcher/src/Matcher/ChainMatcher.php(32): Coduo\PHPMatcher\Matcher\StringMatcher->canMatch('')
#5  in vendor/coduo/php-matcher/src/Parser.php on line 248

With PHP Matcher 2.4 works as expected, returning false.

git bisect says that this is the culprit: #104, mainly, introducing typeints to Coduo\PHPMatcher\Parser::unexpectedSyntaxError.

Indeed, rolling back to a commit before that PR makes everything work again.

However, it may be possible that introducing type hints to Coduo\PHPMatcher\Parser::unexpectedSyntaxError revealed a deeper issue somewhere else in the code.

Seems that it's already fixed by #119.

@norzechowicz Can we get a 3.0.1 tag with the fix? :)

@emodric sure, I will first need to cherry pick #119 to 3.0 branch and then I can tag 3.0.1.
I will do my best to make it available asap
Thanks for reporting and investigation 🍻

Thank you @norzechowicz! 🍻

https://github.com/coduo/php-matcher/releases/tag/3.0.1 here you go, please let me know if it works now!

Thanks @norzechowicz, it works fine 🎉