php – Fatal error: Call to a member function ola() on a non-object


I need to use libraries in Codeigniter version 2.1.4 and I'm having problems using these own libraries. After loading the library (with $this->load->library('Nomedabiblioteca'); in my controller ), I have the line of code:

$a = $this->Nomedabiblioteca->teste();

To receive the return from the teste() method of the class. However, in this line of code, the controller returns the following error:

"Call to a member function test() on a non-object".

How can I resolve this situation? What am I doing wrong?

The library code is as follows (test code):

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Nomedabiblioteca{
    public function teste(){
        $a = 'algo';
        return $a;


I managed to solve this by changing the class name from

$a = $this->Nomedabiblioteca->teste(); //Capitalizada


$a = $this->nomedabiblioteca->teste();

Apparently codeigniter doesn't work for libraries the same way it works for controllers, models and views.

Scroll to Top