zordius / lightncandy

An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ),
https://zordius.github.io/HandlebarsCookbook/
MIT License
610 stars 76 forks source link

The problem in PHP8 #348

Closed mitsh closed 3 years ago

mitsh commented 3 years ago

This issue has appeared after upgrading to PHP8.

Parse error: syntax error, unexpected token "*" in /tmp/lci_7myMwD on line 2

I did a search and found the problem and I made a change in this file; ./src/vendor/lightncandy/Exporter.php

/**
 * Get metadata from ReflectionObject
 *
 * @param object $refobj instance of the ReflectionObject
 *
 * @return array
 */
public static function getMeta($refobj)
{
    $fname = $refobj->getFileName();
    $lines = file_get_contents($fname);
    $file = new \SplFileObject($fname);
    // $file->seek($refobj->getStartLine() - 2);     <-- this is the old one
    $file->seek($refobj->getStartLine() - 1);
    $spos = $file->ftell();
    //     $file->seek($refobj->getEndLine() - 1);   <-- this is the old one
    $file->seek($refobj->getEndLine());
    $epos = $file->ftell();
    unset($file);
    return array(
        'name' => $refobj->getName(),
        'code' => substr($lines, $spos, $epos - $spos)
    );
}

Is this a correct way to fix it?

VascularEngineer commented 3 years ago

This is also helping for me. I'm also on php 8. Not sure if it is the right way to go, I hope we get some feedback on that. I had a similar error, mine was

CRITICAL: Uncaught Exception ParseError: "syntax error, unexpected token ","" at /tmp/lci_Z3NgN8 line 14 {"exception":"[object] (ParseError(code: 0): syntax error, unexpected token \",\" at /tmp/lci_Z3NgN8:14)"}

yurikuzn commented 3 years ago

My fix. Not tested enough yet: https://github.com/yurikuzn/lightncandy/commit/207d424c4ced34644663fdc0758c19d5b6974adc

danmcadams commented 3 years ago

I actually came across this and ended up doing the same thing you did. The problem is the change isn't backwards compatible.

cleoclatskid commented 3 years ago

Just tried out the above fix yurikuzn@207d424 and it works nicely! Thanks

kohlerdominik commented 3 years ago

My fix. Not tested enough yet: yurikuzn@207d424

Works for me, too. Can you make a PR from this @yurikuzn ?

yurikuzn commented 3 years ago

Done: https://github.com/zordius/lightncandy/pull/351

mitsh commented 3 years ago

@yurikuzn's approach is more compatible than mine. so, we can close this issue.