Welcome Guest, Not a member yet? Register   Sign In
Error handling for undefined methods
#1

[eluser]Unknown[/eluser]
Sometimes it happens that I have a typo in the call to one of my libraries' method.

Example:

// Load my library
$this->load->library('something');
// Call an undefined method
$this->something->undefined_method();

Every time this happens, all I get is a blank page. No error message, nothing in the log files, nothing in Apache's log either. There's clearly no indication of what the error is. Then I start polluting my code with die("we got here") statements to figure out where the application flow was ended.


Is there not a proper way to error out on these situations ?


This is by far the biggest ache I have with CodeIgniter (well, the only one, really).

It's interesting that, if I try to access an undefined property (vs a method), then I get a proper error message. But it doesn't hold for undefined method calls.

Am I missing something here ?
#2

[eluser]OliverHR[/eluser]
Well usually when this happen will get a message like this on the browser:

Code:
Fatal error: Call to undefined method Class_name::method_name()
in C:\website\application\controllers\class_name.php  on line 12
#3

[eluser]Unknown[/eluser]
But I don't Sad

From your sample error msg, it seems this is issued when we call a non-existing method from *inside* the class.

My problem is when I instantiate the class with the "load" library, just as I outlined in the OP, then call a public method from outside the instantiated class.

Example:

FILE: /application/libraries/Samplelib.php
Code:
class Samplelib {

  function Samplelib()
  {
    // whatever
  }

  function foo()
  {
    // whatever
  }
};

FILE: /application/controllers/test.php
Code:
class Testlib extends Controller
{
  function Testlib()
  {
    // whatever
  }
  
  function index()
  {
    $this->load->library('samplelib');
    $this->Samplelib->foo(); // ---> defined   --> OK
    $this->Samplelib->bar(); // ---> undefined --> BLANK PAGE !
  }
};
#4

[eluser]danmontgomery[/eluser]
__call works in php5.

Code:
class Samplelib {

  function Samplelib()
  {
    // whatever
  }

  function __call($name, $arguments)
  {
    show_error("Undefined function: " . $name);
  }

  function foo()
  {
    // whatever
  }
};
#5

[eluser]OliverHR[/eluser]
In application config file set a Threshold logging value greater than zero:

Code:
$config['log_threshold'] = 4;

This ache (as you call), is not a CodeIgniter error.




Theme © iAndrew 2016 - Forum software by © MyBB