denissimon / formula-parser

Parsing and evaluating mathematical formulas given as strings.
MIT License
76 stars 24 forks source link

Uninitialized string offset #6

Closed vdomah closed 4 years ago

vdomah commented 4 years ago

Hi! I'm getting this error: Uninitialized string offset: 2:620 in FormulaParser. Analyzed the sources but I can't understand why I'm getting this. The formula is x-y+2 Please help, thanks!

denissimon commented 4 years ago

Hi! What is your PHP version? I cannot reproduce this error at the moment.

denissimon commented 4 years ago

Anyways, you can try the following code for the function match1:

private function match1($matches) {
    $result = $matches[0][0] . '( ( '.substr($matches[0],1,1).' ) )';
    if (isset($matches[0][2])) {
        $result = $result . $matches[0][2];
    }
    return $result;
}

Please let me know if it works without any warnings.