Quoting this answer, which came up when I searched for your error message: (emphasis mine)
You cannot use “use” where you are using it.
The “use” keyword is either in front of a class definition to import other classes/interfaces/traits into it’s own namespace, or it is inside the class (but not inside a method) to add traits to the class.
The use
has to be outside of the function I presume you are calling it in. Something like this should work
<?php
use \Aws\Polly\PollyClient;
// some code
function myfunc() {
require_once ('/polly/aws-autoloader.php');
// rest of the code
}
It should be no problem that you require the autoloader after the use
keyword. After all, it only expands PollyClient
to \Aws\Polly\PollyClient
when you use it in the code.
Related Posts:
- Check if a menu is empty?
- Use template for posts with a particular category grandparent
- Can I change a variable in a content part while calling it?
- Add a Second Menu to a theme that only support 1 menu
- Custom excerpt function re-factoring
- functions.php is being included twice, creating PHP fatal errors
- code is skipping a div
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- PHP include is only working in certain places in my custom WP theme
- Use WordPress function in php file
- Adding wrapper elements in the_date() like in the_title()?
- How to call multiple functions from multiple files into a WordPress page template [closed]
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Create page template via functions.php?
- add_filter function concatenate string and locate_template function
- Template Loop – add switch case php
- Splitting the_content() by size?
- Include a file that has a function in it
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- How do I call an external php non WordPress class into functions.php?
- Display metabox galleries on specific page template in admin editor
- require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
- Before & After Content – After Content directly below Before Content when using require_once
- How to include a function in a template with template tag
- PHP get_category() function redeclared
- Shortcode to include PHP file, pass various parameters to include?
- Loop on a wordpress Page instead of content coming from the WP text editor
- How does printf( __( ) ); work?
- Return HTML Template Page with PHP Function
- Displaying Logged-In User Name in WordPress Menu
- Set media upload attachment link to none and hide it in WP v3.5
- One button to change all settings in theme customizer?
- Add custom image sizes to media uploader
- On this day PHP code
- How to add default images into theme customizer image control?
- Is $hook a global variable in WordPress
- Successful or Error Message after running mysql code in functions.php
- How can one utilize a variable as a callback function name for add_settings_field
- Change title and meta description in included page (not template)
- Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
- Link to file in plugin directory from wordpress template?
- Include a php file from functions.php only to homepage
- How to restrict page access to logged-in users?
- Handling Body class based on Template
- Adding Default Settings to Theme My Login plugin
- Mass update excerpt
- Get post id in a function when edit/add a post
- function to assign user role based on a field from usermeta
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- WordPress Gravatar filter is removing my custom attributes
- Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
- Copyright info change – Corporate Plus Theme PHP [closed]
- How to list posts from a plugin taxonomy?
- Filtering a function’ output for a new continued function
- Shortcode to find and replace URL
- Deleting Certain terms from appearing on the front end as links
- first instantiated SimplePie object cosumes 5mb?
- Theme not calling Jquery properly
- How to set a template with wp_insert_post
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- WordPress redirect redirecting too many times or not at all
- Add value to new attribute inside WordPress menu items
- Please show me how to use an if/else statement in combination with wp_enqueue
- If Array Values Match Another Array’s Values, Then
- Open and closed function [closed]
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- Else/If Statement to Display Photo Descriptions
- Count foreach and display in menu php
- Display additional page templates and a sidebar on plugin activation
- Remove role of user after X days
- User filter posts by year
- bp-custom.php is not working on a WordPress multisite environment. how to fix it?
- Add a Metabox checkbox to the Page Edit screen of wp-admin , which only certain roles can see and Makes only certain roles able to Edit said page
- Adding wp users ID into a link address from a DIVI modul
- Execute function only for specific user roles
- if get_post_meta is empty echo a placeholder or shortcode
- Limit Search to Product Pages only unless I’m on Blogpage or Blogposts
- WP query posts BUT show the most recent and one per author
- Block error message in foreach loop when looping through ACF field
- Include User ID in iFrame URL
- PHP multiple forms, same page, isset($_POST[]) not working?
- Outputting post content to jQuery .html() string
- shortcodes, custom php and their errors
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Remove node from multisites?
- Add ID to output only for first option
- How to add custom text near category/tag title in WordPress Twenty Fifteen Theme?
- Display text of price (minus 20%) on every product page in a sentence.
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- How to make 2 similar functions more efficient
- Echo multiple tasks if a common function exists
- Add end mark at the end of every article
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- Global variables and re-use
- Issues separating my Plugin pages into different files
- Setting WooCommerce currency programmatically
- Masking external links with internal link for member-only
- Automatically change insurance quantity based on cart total [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?
- hiddenQuestions.find is not a function