which then invokes my implementation function, that has this signature
function bhaa_process_wpuser_for_attendee(EE_SPCO_Reg_Step_Attendee_Information $spco, $valid_data)
and EE_SPCO_Reg_Step_Attendee_Information is defined within the EventEspresso plugin. I’m getting this error
[08-Dec-2018 14:00:23 UTC] PHP Fatal error: Uncaught TypeError: Argument 1 passed to BHAA\core\eventexpresso\EventExpresso::bhaa_process_wpuser_for_attendee() must
be an instance of BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information, instance of EE_SPCO_Reg_Step_Attendee_Information given,
called in /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php on line 286 and defined in /home/bhaa/projects/bhaa_wordpress_plugin/src/core/eventexpresso/EventExpresso.php:61
Stack trace:
#0 /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php(286): BHAA\core\eventexpresso\EventExpresso->bhaa_process_wpuser_for_attendee(Object(EE_SPCO_Reg_Step_Attendee_Information), Array)
#1 /home/bhaa/projects/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
#2 /home/bhaa/projects/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /home/bhaa/projects/wordpress/wp-content/plugins/event-espresso-core-reg/modules/single_page_checkout/reg_steps/attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.ph in /home/bhaa/projects/bhaa_wordpress_plugin/src/core/eventexpresso/EventExpresso.php on line 61
I suspect i need to ‘import’ or declare in my php class a ‘use’ declaration to the ‘EE_SPCO_Reg_Step_Attendee_Information’ class but i’m unsure how to handle this with PSR-4 namespacing. Any help would be appreciated.
To be clear, my plugin uses composer to build it’s autoload classpath. I guess the question become, how can i add the event espresso classes i need to the composer autoloader.
Your function is declaring the type of object required:
function bhaa_process_wpuser_for_attendee(EE_SPCO_Reg_Step_Attendee_Information $spco, $valid_data)
Remove EE_SPCO_Reg_Step_Attendee_Information from the above as it’s looking within your own classes namespace for that class, which is why you get this error:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to BHAA\core\eventexpresso\EventExpresso::bhaa_process_wpuser_for_attendee() must
be an instance of BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information, instance of EE_SPCO_Reg_Step_Attendee_Information given,
It’s saying the object given to the hook is an instance of EE_SPCO_Reg_Step_Attendee_Information rather than an instance of your BHAA\core\eventexpresso\EE_SPCO_Reg_Step_Attendee_Information
Either remove that and check $spco is instanceof EE_SPCO_Reg_Step_Attendee_Information within your function:
Hi Tony,
Yes, removing the EE_SPCO_Reg_Step_Attendee_Information class name from the method signature avoids the initial fatal error. I did add the ‘use …LoaderFactory’ but it doesn’t help. I believe i need to declare ‘eventespresso/event-espresso-core’ within my composer.json file, this will ensure there is a version of the EE_SPCO_Reg_Step_Attendee_Information class available on my classpath. Any advice on this would be appreciated.
I checked with the developers and the only change you need to make is to add \ to the EE class name so it uses the root namespace.
Or add use EE_SPCO_Reg_Step_Attendee_Information; (preferable) to the top of the file as then you know it’s using another namespace straight away.
I believe i need to declare ‘eventespresso/event-espresso-core’ within my composer.json file, this will ensure there is a version of the EE_SPCO_Reg_Step_Attendee_Information class available on my classpath.
This won’t help, it’s not an issue with your composer config, it’s incorrect usage of a class.
Any non-namespaced implementations within your namespaced class are assumed to be from that namespace, EE_SPCO_Reg_Step_Attendee_Information is not, it’s in the root namespace so you need to declare namespace, either by adding \ to the class or importing with use above.
Thanks for that. I still had issues with the suggested solutions. At this stage I’m going to use the ‘FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item’ filter since it passes me the required data in a standard php array.
Best Regards and this thread can be closed.
Paul
Viewing 5 reply threads
The support post ‘How to declare 'EE_SPCO_Reg_Step_Attendee_Information.class' as usable?’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.