Cannot include PHP file from WordPress theme folder

Solution:1

You’re trying to include by URL. You need to include by the file’s path (not the uri):

<?php
    $stylesheet_root = get_stylesheet_directory();
    include( $stylesheet_root . '/myfile.php' );
?>

Read more about get_stylesheet_directory() in the docs.

Solution:2

If you check https://codex.wordpress.org/Function_Reference/get_template_directory_uri

You will see get_template_directory_uri() returns a uri, not a server path.

You should use instead the get_template_directory() function:

include get_template_directory() . 'subdir/filename.php';

For a plugin you can use the plugin_dir_path() function:

include plugin_dir_path( __FILE__ ) . 'subdir/filename.php';