10
votes

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);
    }
1
Linux is case sensitive, windows not, are you use its class name "phpass" not "Phpass" - Utku Yıldırım
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. - max_
Error tells us its looking for "Phpass" not phpass - Utku Yıldırım
Yes, but it's not possible considering the code I am using. I'm not calling Phpass anywhere in my code, only phpass - max_
can you paste first lines of phpass.php file where its contructor visible - Utku Yıldırım

1 Answers

35
votes

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