Error with “use” statement – unexpected token “use” in … eval()’d code
-
I am getting an error when trying to add the “use” statement when working with namespaces. I have a file, snippet.php, that contains:
<?php namespace Foo; class Bar { public function __construct() { echo "This is Foo\Bar::__construct().<br/>\n"; } }Then in XYZ PHP Code, I create a snippet like this:
<?php ini_set('display_errors', 1); include_once "/home/[username]/public_html/snippet.php"; $bar = new Foo\Bar();This works. However, when I attempt to add a “use” statement in the snippet code instead of the Foo prefix:
<?php ini_set('display_errors', 1); require_once("/home/[username]/public_html/snippet.php"); use Foo\Bar; $bar = new Bar();Then I get an “unexpected token” error:
Parse error: syntax error, unexpected token “use” in /home/[username]/public_html/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(99) : eval()’d code on line 4
There has been a critical error on this website.Does anyone know what the issue here is? Is there some conflict with this plugin and “use” statements? Can you use “use” statements with this plugin?
I have WordPress 6.1.1, and PHP Code Snippet 1.3.3.
The topic ‘Error with “use” statement – unexpected token “use” in … eval()’d code’ is closed to new replies.