PHP Editor error - Parse error: syntax error, unexpected '[' in /var/www/html/md/editor/lib/Database

PHP Editor error - Parse error: syntax error, unexpected '[' in /var/www/html/md/editor/lib/Database

peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0
edited May 2019 in Free community support

That's it, error PHP Editor error - Parse error: syntax error, unexpected '[' in /var/www/html/md/editor/lib/Database

This is with a working datatable (no editor function...) on the page and intialising editor with:

include( "../editor/lib/DataTables.php" );
use DataTables\Editor;
$editor = Editor::inst( $db, 'unit', 'unit_pk' )
    ->fields(
        Field::inst( 'unit_name' ),
        Field::inst( 'points' ),
        Field::inst( 'year' )
    )
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    Hi @peterbrowne ,

    I think it's because you're not using all the classes. To be sure, could you change

    use DataTables\Editor;
    

    to be

    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    

    I don't think you need them all, but it'll tell us if we're on the right path!

    Cheers,

    Colin

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0
    edited May 2019

    Still have the same error:

    "Parse error: syntax error, unexpected '[' in /var/www/html/md/editor/lib/Database.php on line 136 "

    I am using:

    include( "../editor/lib/DataTables.php" );
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    $editor = Editor::inst( $db, 'unit', 'unit_pk' )
        ->fields(
            Field::inst( 'unit_name' ),
            Field::inst( 'points' ),
            Field::inst( 'year' )
        )
        ->process( $_POST )
        ->json();
    
  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    The error indicates this line, but that is valid PHP.

    What version of PHP are you using please?

    Allan

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

    PHP Version 5.3.3

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

    Parse error: syntax error, unexpected '[' in /var/www/html/md/editor/lib/Database.php on line 136

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    That's a really old version now (10 years ago :)) and hasn't seen security updates in a good while.

    Are you able to update to a newer version? Even if its just 5.3.29. I recall having issues with some of the earlier 5.3.x releases before.

    Allan

  • peterbrownepeterbrowne Posts: 314Questions: 54Answers: 0

    Admin is not upgrading, so I'm stuck at 5.3.3

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    As it's the best you can get with RHEL6 ... may want to update the requirements on the recent version of Editor :(

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    It is possible to install PHP 5.6 using SCL (details), however I agree - I'll mark that the latest version of PHP 5.3 is required.

    @jacob.steinberger Are you also seeing the same error and the same line number?

    Allan

  • caesar-ucfcaesar-ucf Posts: 1Questions: 0Answers: 0

    I modify the /lib/database.php on line 136
    It's works,
    //return $res->fetch()['cnt'];
    $row = $sth->fetch();
    $cnt=$row['cnt'];
    return $cnt;

This discussion has been closed.