[BETA] Fatal error: Cannot use Joomla\Utilities\ArrayHelper as ArrayHelper #1061

Closed
opened 2024-02-20 19:46:04 +00:00 by oxido · 7 comments

Steps to reproduce the issue

Create any component
Compile the component
Install the component
Try to access the component from the admin menu.

Expected result

To see the Dashboard of the component

Actual result

Fatal error: Cannot use Joomla\Utilities\ArrayHelper as ArrayHelper because the name is already in use in C:\wamp64\www\j3dev\administrator\components\com_test\controller.php on line 27

System information (as much as possible)

  • OS Name & Version: Windows 11
  • MySql Version: 8.2.0
  • Apache Version: 2.4.58
  • PHP Version: 7.4.33
  • Joomla Version: 3.10.12
  • JCB Version: 3.1.40-beta
  • Browser: Firefox

Additional comments

the beginning of the content of controller.php

use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
### Steps to reproduce the issue Create any component Compile the component Install the component Try to access the component from the admin menu. ### Expected result To see the Dashboard of the component ### Actual result Fatal error: Cannot use Joomla\Utilities\ArrayHelper as ArrayHelper because the name is already in use in C:\wamp64\www\j3dev\administrator\components\com_test\controller.php on line 27 ### System information (as much as possible) - OS Name & Version: Windows 11 - MySql Version: 8.2.0 - Apache Version: 2.4.58 - PHP Version: 7.4.33 - Joomla Version: 3.10.12 - JCB Version: 3.1.40-beta - Browser: Firefox ### Additional comments the beginning of the content of controller.php ``` use VDM\Joomla\Utilities\ArrayHelper; use VDM\Joomla\Utilities\StringHelper; // No direct access to this file defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\MVC\Controller\BaseController; use Joomla\Utilities\ArrayHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; ```
Author

I am not trying to make excuses, but until now I have not tried to understand the Powers.
Is this a suitable solution?
In CJB I went to Powers, edited Utilities Array Helper and changed its name from: ArrayHelper to VdmArrayHelper.
And I also changed the Namespace from
VDM\Joomla\Utilities.ArrayHelper to VDM\Joomla\Utilities.VdmArrayHelper

And now it sims to work, but there is still a problem use VDM\Joomla\Utilities\VdmArrayHelper; is not added to the view file default_vdm.php

And also I know that nothing should be above defined('_JEXEC') or die('Restricted access');

I am not trying to make excuses, but until now I have not tried to understand the Powers. Is this a suitable solution? In CJB I went to Powers, edited Utilities Array Helper and changed its name from: ArrayHelper to VdmArrayHelper. And I also changed the Namespace from VDM\Joomla\Utilities.ArrayHelper to VDM\Joomla\Utilities.VdmArrayHelper And now it sims to work, but there is still a problem `use VDM\Joomla\Utilities\VdmArrayHelper;` is not added to the view file **default_vdm.php** And also I know that nothing should be above `defined('_JEXEC') or die('Restricted access');`
Owner
C:\wamp64\www\j3dev\administrator\components\com_test\controller.php

This is a Joomla 3 path right?

In JCB, I navigated to Powers, edited the Utilities Array Helper, and renamed it from ArrayHelper to VdmArrayHelper.

This is a significant modification, and making such changes without a thorough understanding of how powers operate is risky 😉

The PHP version is currently 7.4.33. Please upgrade to at least PHP version 8.0.0. I have been using PHP 7 for quite some time and wouldn't be surprised if things malfunction or break on that older version.

JCB and Joomla 3.10 is set to run on PHP 8.0+

When examining this controller template, as well as an extension where this file is constructed, everything appears to be correct and is being built as anticipated. This suggests that upgrading your PHP version might resolve the issue.

It's worth noting that JCB itself is constructed using JCB. Thus, the fact that JCB operates smoothly (in the beta branch for Joomla 3.10) is evidence that it's being built correctly most of the time. In fact, all my work is in the beta branch, meaning all my activities and the projects I manage. If the beta branch causes any issues with my projects, I typically notice and rectify them well before releasing the next update.

We have a class that searches the template (data) to identify where to insert the additional namespaces found in the listed powers, such as the Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($ref) value. This class can be observed here, attempting to find the insertion point. If unsuccessful, it places the new use statements below the defined statement. This seems to be the case with your file. This issue likely arose from the need to adjust the regex 'preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);' when transitioning from PHP 7.4 to 8.0+. This explanation delves deeper into our method of adding the powers header (use statements) to the file. This step occurs towards the end of the compiler process, yet sufficiently early to include the file in the package.

The power feature in JCB is incredibly powerful, and it has become my primary tool. It allows for the full integration of PHP with JCB and Joomla. I believe it has resolved a significant challenge for developers, a problem many are not yet aware of. Hence, I understand if you and others haven't taken much interest in the powers feature. However, as your extensions in JCB become more advanced and valuable, you'll find yourself using powers more frequently—it represents the future. Although there are a few tutorials available, I admit I haven't kept everyone fully informed about its progress. Its features are particularly relevant to those managing large-scale JCB projects with around 500k lines of code, integrating with multiple external systems, and surpassing JCB's complexity.

I've begun developing a script that will enable the capturing of powers from various power repositories into a composer package for distribution via the "composer" channel, aiming to bridge our applications across different CMS and framework barriers. The sooner you master the "power" capabilities of JCB, the more remarkable applications you'll be able to create.

``` C:\wamp64\www\j3dev\administrator\components\com_test\controller.php ``` This is a Joomla 3 path right? In JCB, I navigated to Powers, edited the Utilities Array Helper, and renamed it from `ArrayHelper` to `VdmArrayHelper`. This is a significant modification, and making such changes without a thorough understanding of how powers operate is risky 😉 The PHP version is currently 7.4.33. Please upgrade to at least PHP version 8.0.0. I have been using PHP 7 for quite some time and wouldn't be surprised if things malfunction or break on that older version. > JCB and Joomla 3.10 is set to run on PHP 8.0+ When examining this controller [template](https://git.vdm.dev/joomla-beta/com-componentbuilder/src/branch/master/admin/compiler/joomla_3/BaseController.php), as well as an [extension](https://git.vdm.dev/joomla-beta/com-componentbuilder/src/branch/master/admin/controller.php#L19) where this file is constructed, everything appears to be correct and is being built as anticipated. This suggests that upgrading your PHP version might resolve the issue. It's worth noting that JCB itself is constructed using JCB. Thus, the fact that JCB operates smoothly (in the beta branch for Joomla 3.10) is evidence that it's being built correctly most of the time. In fact, all my work is in the beta branch, meaning all my activities and the projects I manage. If the beta branch causes any issues with my projects, I typically notice and rectify them well before releasing the next update. We have a class that searches the template (data) to identify where to insert the additional namespaces found in the listed powers, such as the `Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($ref)` value. This class can be observed [here](https://git.vdm.dev/joomla-beta/com-componentbuilder/src/branch/master/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Injector.php#L524), attempting to find the insertion point. If unsuccessful, it places the new `use` statements [below](https://git.vdm.dev/joomla-beta/com-componentbuilder/src/branch/master/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Power/Injector.php#L575) the `defined` statement. This seems to be the case with your file. This issue likely arose from the need to adjust the regex 'preg_match($pattern, $code, $matches, PREG_OFFSET_CAPTURE);' when transitioning from PHP 7.4 to 8.0+. This explanation delves deeper into our method of adding the powers header (use statements) to the file. This step occurs towards the end of the compiler process, yet sufficiently early to include the file in the package. The power feature in JCB is incredibly powerful, and it has become my primary tool. It allows for the full integration of PHP with JCB and Joomla. I believe it has resolved a significant challenge for developers, a problem many are not yet aware of. Hence, I understand if you and others haven't taken much interest in the powers feature. However, as your extensions in JCB become more advanced and valuable, you'll find yourself using powers more frequently—it represents the future. Although there are a few tutorials available, I admit I haven't kept everyone fully informed about its progress. Its features are particularly relevant to those managing large-scale JCB projects with around 500k lines of code, integrating with multiple external systems, and surpassing JCB's complexity. I've begun developing a script that will enable the capturing of powers from various power repositories into a composer package for distribution via the "composer" channel, aiming to bridge our applications across different CMS and framework barriers. The sooner you master the "power" capabilities of JCB, the more remarkable applications you'll be able to create.
Author

C:\wamp64\www\j3dev\administrator\components\com_test\controller.php
Yes sir, this is a Joomla 3 path.
I was trying to test my component on the same !J3 website, where JCB is installed, to avoid to move back and forward between J3 and J4 😅
Regarding the PHP version (8.0.30), nothing is changing on joomla 3, same problem as before.

I see that the component works if I compile it for !J4&5, but there is still the problem with the missing code use VDM\Joomla\Utilities\ArrayHelper;, is not added to the view file default_vdm.php, witch is the view for Dashboard.
But I can access the other views from admin if the view is set to show in the main menu.

So all of this was the situation on my local server using:
wamp v3.3.2, PHP v8.0.30, Apache v2.4.58, Maria v11.2.2, phpMyAdmin v5.2.1 MySQL 8.2.0

==========================================================================================

I said I'd do some more digging before I post again.
I made a clone of the whole site from the local server and put it on a real server, everything seems to be ok.
I wonder what is causing the problem on my local server?
On the "real server" I even use php 7.4.33 and is still working right...

`C:\wamp64\www\j3dev\administrator\components\com_test\controller.php` Yes sir, this is a Joomla 3 path. I was trying to test my component on the same !J3 website, where JCB is installed, to avoid to move back and forward between J3 and J4 😅 Regarding the PHP version (8.0.30), nothing is changing on joomla 3, same problem as before. I see that the component works if I compile it for !J4&5, but there is still the problem with the missing code `use VDM\Joomla\Utilities\ArrayHelper;`, is not added to the view file default_vdm.php, witch is the view for Dashboard. But I can access the other views from admin if the view is set to show in the main menu. So all of this was the situation on my local server using: wamp v3.3.2, PHP v8.0.30, Apache v2.4.58, Maria v11.2.2, phpMyAdmin v5.2.1 MySQL 8.2.0 ========================================================================================== I said I'd do some more digging before I post again. I made a clone of the whole site from the local server and put it on a real server, everything seems to be ok. I wonder what is causing the problem on my local server? On the "real server" I even use php 7.4.33 and is still working right...
Owner

This is the preferred way to run JCB (in docker) https://www.youtube.com/watch?v=owpxKie0I7s

So we can be sure we are in the same environment "more or less", this is also how I work... only on Ubuntu, and only in Docker.

This is the preferred way to run JCB (in docker) https://www.youtube.com/watch?v=owpxKie0I7s So we can be sure we are in the same environment "more or less", this is also how I work... only on Ubuntu, and only in Docker.
Author

Thank you, after 1 day I managed to Install VirtualBox + Ubuntu and to set the environment following the tutorial from your video, it took me a while but I did it.

It was not a problem to install VirtualBox + Ubuntu and to do what you do in that tutorial, the sad part was after, when I was trying to access the "octoleo.joomla.vdm", or the "port.joomla.vdm", it was not working.
I'm not going to start telling everything, but I think the problem is from "octojoom > Traefik Container", after trying to set it (the first run), I was getting errors like this:
WARN[0007] a network with name traefik_webgateway exists but was not created by compose. Set 'external: true' to use an existing network network traefik_webgateway was found but has incorrect label com.docker.compose.network set to ""
This was my first time trying to use docker, and I installed ubuntu just out of curiosity, a long time ago
In "Docker/traefik", I have edited "docker-compose.yml", and I've changed the code starting with line 37.
DEFAULT

    networks:
      - traefik

networks:
  traefik:
    name: traefik_webgateway

EDITED

    networks:
      - traefik
      - traefik_webgateway

networks:
  traefik:
    name: traefik
  traefik_webgateway:
    external: true
    name: traefik_webgateway

Thank you, I will close this Issue.

Thank you, after 1 day I managed to Install VirtualBox + Ubuntu and to set the environment following the tutorial from your video, it took me a while but I did it. It was not a problem to install VirtualBox + Ubuntu and to do what you do in that tutorial, the sad part was after, when I was trying to access the "octoleo.joomla.vdm", or the "port.joomla.vdm", it was not working. I'm not going to start telling everything, but I think the problem is from "octojoom > Traefik Container", after trying to set it (the first run), I was getting errors like this: `WARN[0007] a network with name traefik_webgateway exists but was not created by compose. Set 'external: true' to use an existing network network traefik_webgateway was found but has incorrect label com.docker.compose.network set to ""` This was my first time trying to use docker, and I installed ubuntu just out of curiosity, a long time ago In "Docker/traefik", I have edited "docker-compose.yml", and I've changed the code starting with line 37. DEFAULT ``` networks: - traefik networks: traefik: name: traefik_webgateway ``` EDITED ``` networks: - traefik - traefik_webgateway networks: traefik: name: traefik traefik_webgateway: external: true name: traefik_webgateway ``` Thank you, I will close this Issue.
Owner

You can bump (open an issue) the octojoom repo directly ;)

You can bump (open an issue) the octojoom repo directly ;)
Owner

So yesterday our in house testing Team found that they could not get a few of our own components to work, it kept missing classes. We then discovered that the installer of Joomla times-out and the complete package does not install, even thought it says that it did. So they asked me what tweaks to PHP I am using on my development system. So here is some of my PHP.ini tweaks:

; Resource Limits and File Uploads
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 60
max_input_vars = 5000
max_input_time = 60
memory_limit = 256M

If you add these, and install JCB again.... and also on the system where your planning to install you component... I think it will resolve your problem. Yes, you could remove this in most cases after the install, but in your development system it might be best to keep it on.

But for large extensions like those that JCB can build making these changes seems necessary, at least on the initial install.

So yesterday our in house testing Team found that they could not get a few of our own components to work, it kept missing classes. We then discovered that the installer of Joomla times-out and the complete package does not install, even thought it says that it did. So they asked me what tweaks to PHP I am using on my development system. So here is some of my PHP.ini tweaks: ``` ; Resource Limits and File Uploads upload_max_filesize = 128M post_max_size = 128M max_execution_time = 60 max_input_vars = 5000 max_input_time = 60 memory_limit = 256M ``` If you add these, and install JCB again.... and also on the system where your planning to install you component... I think it will resolve your problem. Yes, you could remove this in most cases after the install, but in your development system it might be best to keep it on. But for large extensions like those that JCB can build making these changes seems necessary, at least on the initial install.
oxido closed this issue 2024-07-19 00:43:02 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#1061
No description provided.