0

I'm building a wordpress plugin using PHP 7.4 and this function returns error:

Parse error: syntax error, unexpected end of file

PHP has been properly broken out of and all curly brackets are in pairs:

<?php
function my_function()
{
    $jer_ver = filemtime(WP_PLUGIN_DIR . '/somefile.js');
    $style_ver = filemtime(WP_PLUGIN_DIR . '/somefile.css');
    wp_enqueue_script('admin_js', plugins_url('../JS/admin.js', __FILE__), array(), $jer_ver);
    wp_enqueue_style('admin_style', plugins_url('../CSS/admin.css', __FILE__), array(), $style_ver);
    global $wpdb;
?>
//(some html) same error commented and uncommented
<?php
}

Adding an extra curly bracket to the end such as this fixes the error on wordpress but causes PhpStorm to freak out.

...
<?php
}
}

I have also tried adding closing tag ?>

Any suggestions?

1 Answers1

0

I've checked this code multiple times. It's working fine. Maybe you have an error somewhere else. Or you have some code before the my_function() function where there's an extra opening bracket but the closing bracket is missing. Please check the error line number. Please note that, You shouldn't put brackets directly close to the open/close php tag, but separate it with at least one space:

{ ?>
<?php {
Reza Khan
  • 86
  • 3