wp_get_theme Warning: Illegal offset type

The Line

$theme = wp_get_theme();

returns a WP_Theme Object, and you cannot use an Object in an Array like this.

Use

$templates = $themes[$theme->template]['Template Files'];

To get the Array of your template Files. In Order to get this function running again, you also have to change Single Post Template to Template Name:

if (preg_match( '|Template Name:(.*)$|mi', $template_data, $name))

As you did not specify what you want to do with the results, I can’t help you any further, but you should be okay this way for this function.