'spl_auload_register exclude nested classes - PHP

I am auto loading php classes from different folders by using namespace.I use namespace and use to get the desired class name.But there happening a problem requiring the classes files as i am using new WP_Query() class within a class and that function also wants to include WP_Query() class.

Below is the code.. from plugin index.php

namespace WPSEVENT;
use WPSEVENT\includes\Shortcode;

spl_autoload_register(__NAMESPACE__ . '\\autoload');

function autoload($class = '') {
    if (!strstr($class, 'WPSEVENT')) {
        return;
    }
    $result = str_replace('WPSEVENT\\', '', $class);
    $result = str_replace('\\', '/', $result);
    require $result . '.php';
}

and the shortcode class in includes folder..

namespace WPSEVENT\includes;

/**
 * 
 */
class Shortcode
{
    public static $instance;

    public static function smartEventShortCode($atts){
        $vars = extract(shortcode_atts( 
            array(
                'columns' => 4,
                'style'   => 1, 
                'posts_per_page'    => 1,
            ), $atts ));

        $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
        $eventargs = array(
            'posts_per_page'    => $posts_per_page,
            'post_type'         => WP_SEVENT_SLUG,
            'paged'             => $paged,
        );

        $posts = new WP_Query($eventargs);
        $html = '<div class="row">';
        if($posts->have_posts()){
            while ($posts->have_posts()) {
                $posts->the_post();
                switch ($style) {
                    case '1':
                        //$html .= self::getStyleOne( $columns, $postdata );
                        break;
                }
            }
        }
        $html .= '</div>';
        return $html;
    }
}

And the error i am getting

Fatal error: Class 'WPSEVENT\includes\WP_Query' not found

What i expect is to exclude the WP_Query class



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source