Traits do not seem to load properly in classes #942

Open
opened 2022-08-02 15:24:00 +00:00 by SimonvanDoorne · 3 comments
Member

Steps to reproduce the issue

  1. Create Class (in my case Umhelper) in powers area of JCB
  2. Load 'Utilities' trait into class (one of the items that are imported when you load the powers into JCB)
    image
  3. the traits gets added to the use list
    image

Expected result

  1. checking what traits are used using the code
    $helper = new Umhelper(); echo '<pre>'; var_dump(class_uses($helper)); die;
  2. Result should be
    array(1) { ["VDM\Joomla\Utilities"]=> string(20) "VDM\Joomla\Utilities" }

Actual result

  1. Instead result is
    array(0){}

  2. If i move the use of utilities inside the class and add a backslash it works
    image

Then using class_uses($helper) results in

array(1) { ["VDM\Joomla\Utilities"]=> string(20) "VDM\Joomla\Utilities" }

System information (as much as possible)

  • OS Name & Version:
  • MySql Version:
  • Apache Version:
  • PHP Version: 7.4
  • Joomla Version: 3.10.10
  • JCB Version: 3.1.4
  • Browser: Firefox

Additional comments

Using my own created traits results in the same behaviour as mentioned above. I haven't used traits in a while so if i'm doing something wrong here i would not be surprised.

### Steps to reproduce the issue 1) Create Class (in my case Umhelper) in powers area of JCB 2) Load 'Utilities' trait into class (one of the items that are imported when you load the powers into JCB) ![image](/attachments/05f44e99-d702-4d0c-87ab-51b873db4d83) 3) the traits gets added to the use list ![image](/attachments/a9f3a367-ea4e-43d2-8602-ceda932cda6d) ### Expected result 1) checking what traits are used using the code ` $helper = new Umhelper(); echo '<pre>'; var_dump(class_uses($helper)); die; ` 2) Result should be `array(1) { ["VDM\Joomla\Utilities"]=> string(20) "VDM\Joomla\Utilities" }` ### Actual result 1) Instead result is `array(0){}` 2) If i move the use of utilities inside the class and add a backslash it works ![image](/attachments/8f599bfd-cd52-45f4-a9ff-3c2d4f4e4db9) Then using class_uses($helper) results in `array(1) { ["VDM\Joomla\Utilities"]=> string(20) "VDM\Joomla\Utilities" }` ### System information (as much as possible) - OS Name & Version: - MySql Version: - Apache Version: - PHP Version: 7.4 - Joomla Version: 3.10.10 - JCB Version: 3.1.4 - Browser: Firefox ### Additional comments Using my own created traits results in the same behaviour as mentioned above. I haven't used traits in a while so if i'm doing something wrong here i would not be surprised.
Owner

Please upgrade your Plugins, as I can see your still on an older version of the header plugins. This is how it should look like:

image

Let me know once you have all upgrade, your still having this issue.

Please [upgrade your Plugins](https://git.vdm.dev/joomla/pkg-component-builder), as I can see your still on an older version of the header plugins. This is how it should look like: ![image](/attachments/2d68191b-4f72-4d0b-b464-b7929a11b320) Let me know once you have all upgrade, your still having this issue.
Author
Member

I re-downloaded the JCB package and confirmed that all the plugins are the same version as the ones in your link but I may not have been clear. The first image is a screenshot from inside the Umhelper class in the powers area. When i look inside an admin view tab 'class headers' i see the following:
image

I re-downloaded the JCB package and confirmed that all the plugins are the same version as the ones in your link but I may not have been clear. The first image is a screenshot from inside the Umhelper class in the powers area. When i look inside an admin view tab 'class headers' i see the following: ![image](/attachments/ff930bb9-90de-4701-a64b-2bb88c1b7f9d)
Owner

I just realize what the issue is here, JCB does not yet add the trait to the class, it only addes it as use namespace (auto loader) to the header of the file.

But I can understand that this behaviour your looking for is what whould be naturally expected. So lets add this issue as a feature request and add this automation in, so JCB will add the trait to the class code ready to use... if it detects that you have not done so already.

I just realize what the issue is here, JCB does not yet add the trait to the class, it only addes it as use namespace (auto loader) to the header of the file. But I can understand that this behaviour your looking for is what whould be naturally expected. So lets add this issue as a feature request and add this automation in, so JCB will add the trait to the class code ready to use... if it detects that you have not done so already.
Llewellyn added this to the Major improvement to core (speedup production) milestone 2022-08-03 08:54:54 +00:00
Llewellyn added the
enhancement
label 2022-08-03 08:55:09 +00:00
Llewellyn self-assigned this 2022-08-03 08:55:15 +00:00
Llewellyn added the due date 2022-09-30 2022-08-03 08:55:52 +00:00
Llewellyn added this to the Compiler Improvements project 2022-08-03 08:56:39 +00:00
Llewellyn modified the project from Compiler Improvements to Feature Requests 2022-08-05 08:36:18 +00:00
Sign in to join this conversation.
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

2022-09-30

Dependencies

No dependencies set.

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