[BUG]: syntax error, unexpected token "use" #[\AllowDynamicProperties] #1193
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#1193
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What Happened?
After updating to v5.0.4-alpha this error occures.
syntax error, unexpected token "use" in
JROOT\administrator\components<component_name>\src\View<views>\HtmlView.php:47
It occures in all admin views and view
Steps to reproduce the Bug
HtmlView file views and view
Problem seems to be the order of the use statements related to #[\AllowDynamicProperties]
...
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Document\Document;
use JCB\Component<component_name>\Administrator\Helper<component_name>Helper;
// No direct access to this file
\defined('_JEXEC') or die;
/**
*<component_name> Html View class for the
*
*/
#[\AllowDynamicProperties]
use JCB\Joomla\Utilities\ArrayHelper;
use JCB\Joomla\Utilities\StringHelper;
Changing the statement by moving it to the other use statements, seems to fixe the issue.
...
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Document\Document;
use JCB\Component<component_name>\Administrator\Helper<component_name>Helper;
use JCB\Joomla\Utilities\ArrayHelper;
use JCB\Joomla\Utilities\StringHelper;
// No direct access to this file
\defined('_JEXEC') or die;
/**
*/
#[\AllowDynamicProperties]
Which Joomla version are you compiling in?
5.1.1.
Which PHP version are you compiling in?
8.1
Which Joomla versions are you targeting?
5.1.1.
Which PHP version are you targeting?
8.1
Which Web server is JCB running on?
Apache/2.4.58
Which Relational Database is JCB running on?
10.4.32-MariaDB
Which OS is JCB running on?
xampp
Which JCB version are you using?
5.0.4-beta1
Where in JCB did this issue occur?
Joomla Components(admin_views), Joomla Modules(admin_views)
On which browsers did you encounter the issue?
Firefox
Additional Comments
No response
Thank you for the detailed report and for taking the time to investigate this issue! After a thorough review, I can confirm that the structure of JCB-generated files adheres to Joomla's coding conventions. Specifically:
Placement of
#[\AllowDynamicProperties]
: The attribute is placed directly above the class declaration in all JCB-generated files, consistent with Joomla's core classes such asBaseModel
in Joomla 5.3. This placement is valid PHP syntax.Placement of
use
Statements: In both Joomla and JCB,use
statements are placed above the\defined('_JEXEC') or die;
declaration. This structure is intentional and standard across all JCB-generated files.Possible Cause: Super Power Feature
One possibility to consider is JCB's Super Power feature, which dynamically adds
use
statements to files. If this feature is active, it could be incorrectly placing additionaluse
statements in the file, resulting in a syntax error. This would explain why the file works initially but encounters issues after dynamic modifications.Why This Needs More Investigation
JCB itself, as well as its generated files, follow this structure and are known to work. Since the error isn’t reproducible in a standard JCB environment, we’ll need more information to pinpoint the issue. The following steps will help us clarify what’s happening:
Suggested Steps to Troubleshoot
Inspect the Affected File: Please review the file where the error is occurring and compare it to the originally generated file in JCB. Specifically, check for:
use
statements added by the Super Power feature.use
statements added after the#[\AllowDynamicProperties]
attribute or in unexpected locations.Validate Syntax: Run
php -l <file>
on the affected file to check for syntax errors. This can confirm if the placement of dynamically addeduse
statements is causing the issue.Environment-Specific Behavior: While PHP 8.1 fully supports attributes, XAMPP or other local environments can sometimes behave inconsistently. Testing the component on a different environment (e.g., Docker or a production-like server) may help rule out environment-specific issues.
Provide the Full File for Review: If possible, share the full content of the affected file, including any changes made dynamically by the Super Power feature. This will allow us to compare it against the intended structure and identify any discrepancies.
Suggested Fix if Super Power Feature is the Issue
If the Super Power feature is indeed adding
use
statements incorrectly, the solution would involve:use
statements are placed above the\defined('_JEXEC') or die;
declaration and before the#[\AllowDynamicProperties]
attribute.Next Steps
To summarize:
use
statements by the Super Power feature, syntax errors elsewhere, or environment-specific behavior.We’ll need more details about the specific file where the issue occurs, including whether it was modified dynamically or manually. Please share the full content of the file, any stack traces, or other relevant information to help us investigate further.
Thank you for your patience and collaboration! Let me know if there’s anything else I can assist with.