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
- Login/logout in header
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- Mass update excerpt
- How does WordPress insert Paragraphs in posts
- WordPress Access allowed to fewer pages till user logs in
- Linking text within textarea of custom meta box
- Show css depending on activity type in BuddyPress activity-loop [closed]
- only show container with next/prev links if they exist?
- How to combine wordpress_logged_in cookies in one cookie?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Change the WP Video Shortcode Output
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- remove wp floating submenu in wp dashboard
- How to put “Read more” link in Custom Excerpt inside p tag?
- Two Different Links for Same Product – WooCommerce [closed]
- ACF: how do I get the fields and its values of a specific group?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Get value from shortcode to do something
- How can I get a single php file that is the equivalent of an existing WordPress page?
- PHP 8, AJAX mail form to function.php doesn’t work
- How do I add custom bulk actions to multiple custom post types?
- Error when adding excerpt to the content through functions.php
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Get post id in a function when edit/add a post
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- How to check if a meta value has already been assigned to any user?
- How to complete two other input fields, completed the first
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- How can I apply_filters from inside a function?
- Get and insert order email address to the PHP template inside HTML text
- function to assign user role based on a field from usermeta
- what is the best practice to add new field to an api route
- Custom search results page not working with empty search
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Pass Category Name, Description and Photo into variables to pass to jQuery
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Use DOMDocument with ob_start breaks my HTML code
- Auto-update products after they were published – Woocommerce
- How to prevent WP_Query function from returning all posts when empty?
- How to show single category archive
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- JS file work only in index page
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Removing “wpautop” (auto tags) only on certain pages?
- Fatal error: Uncaught Error: Call to undefined function test()
- How to pick the default selected value in wordpress dropdown?
- Using WP-API and SSE not authenticating user ID
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Validate functions before inserting then into functions.php
- How to retrieve current wordpress profile page URL?
- Firing schema via code in functions.php doesn’t work
- Issues getting PHP to display in category pages
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Get page that displays all children of taxonomy parent
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- get author_name from queried post
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to call plugin function per site in a multisite?
- Print last modified date only on posts
- different id for same element visual composer [closed]
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- Tax query in pre_get_posts not working
- WordPress Gravatar filter is removing my custom attributes
- foreach loop still echoes array