1

I'm new to php & developing php5.4 application.there i used auto loading classes.I get a fatal error so I assume it doesn't work function _autoload properly.. Please find below the code I used. When I tried it gave me the following error: please help me.

Fatal error: Class 'User' not found in C:\Program Files\xampp\htdocs\MVCApp\index.php on line 35 

C:\Program Files\xampp\htdocs\MVCApp\index.php file

<?php

        //define('APPLICATION_PATH', realpath('../'));//C:\Program Files\xampp\htdocs
         define('APPLICATION_PATH', realpath('../'));//C:\Program Files\xampp\htdocs\MVCApp

        echo APPLICATION_PATH;

        $paths=array(
            APPLICATION_PATH,
            APPLICATION_PATH.'/com',
            get_include_path(),


        );
        set_include_path(implode(PATH_SEPARATOR, $paths));

       // echo get_include_path();//C:\Program Files\xampp\php\PEAR

        function _autoload($className)
       {
          require_once $className.'.php';
          return;
       }


          $user=new User();

          echo $user->getName();


        ?>


        C:\Program Files\xampp\htdocs\MVCApp\com\User.php file

        <?php

C:\Program Files\xampp\htdocs\MVCApp\com\User.php file

<?php

class User {

    public function getName()
    {
       return 'Hello Sam';
    }
}

1 Answer 1

3
function __autoload($className)
           {
                echo $className;


           }

autoload function works with two underscores.not one.Now i think it should be work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.