CodeIgniter - unable to load requested class

75,554

I think the capitalisation of your file name and class name is the issue, according to the user guide:

  • phppass.php should be Phppass.php
  • class phpass should be class Phpass
Share:
75,554
max_
Author by

max_

Engineering Lead

Updated on March 31, 2020

Comments

  • max_
    max_ about 4 years

    Yes, I imagine you are thinking to say that this question is a possible duplicate, however it isn't as the answers for the similar questions do not fix the issue I am currently having.

    I'm receiving the following error while autoloading a library named 'phpass' as follows.

    An Error Was Encountered Unable to load the requested class: Phpass

    Code to autoload the library

    $autoload['libraries'] = array('database', 'phpass');
    

    The phpass.php file resides in the application/libraries folder, and the class is declared as class phpass meaning that the issue cannot be related to capitalisation or the file path as suggested in the majority of other answers I have come across.

    Please can you tell me what I am missing? It works perfectly in MAMP, however, when uploading to my Linux Ubuntu server (Apache2), it stops working.

    Thanks,

    Max.

    Edit--- Constructor method as requested by Utku

    class phpass {
    
        protected $PasswordHash;
    
        // default values if config was not found
        protected $iteration_count_log2 = 8;
        protected $portable_hashes = FALSE;
    
        /**
         * Construct with configuration array
         * 
         * @param array $config
         */
        public function __construct($config = array()) {
            // check if the original phpass file exists
            if (!file_exists($path = dirname(__FILE__) . '/../vendor/PasswordHash.php')) {
                show_error('The phpass class file was not found.');
            }
    
            include ($path);
    
            if (!empty($config)) {
                $this->initialize($config);
            }
    
            // create phpass object
            $this->PasswordHash = new PasswordHash($this->iteration_count_log2, $this->portable_hashes);
        }
    
    • Utku Yıldırım
      Utku Yıldırım almost 11 years
      Linux is case sensitive, windows not, are you use its class name "phpass" not "Phpass"
    • max_
      max_ almost 11 years
      I ruled out the error being as a result of the filename, and I'm running on Mac, not windows, hence using MAMP not WAMP.
    • Utku Yıldırım
      Utku Yıldırım almost 11 years
      Error tells us its looking for "Phpass" not phpass
    • max_
      max_ almost 11 years
      Yes, but it's not possible considering the code I am using. I'm not calling Phpass anywhere in my code, only phpass
    • Utku Yıldırım
      Utku Yıldırım almost 11 years
      can you paste first lines of phpass.php file where its contructor visible
    • max_
      max_ almost 11 years
      I've updated the question with the constructor.
  • max_
    max_ almost 11 years
    Yes, brilliant. Thanks @lefters!
  • jleft
    jleft almost 11 years
    No problem at all @max_! I'm glad this helped!