Welcome Guest, Not a member yet? Register   Sign In
Can not extends core Exception.php

Hi, I'm trying to extend the Exception but always receive Fatal error: Call to undefined function. I tried to add function to both the system/core and application/core/MY_Exceptions.php. Both failed.

class MY_Exceptions extends CI_Exceptions

//                        function __construct()
//                        {
//                                                parent::__construct();
//                        }

                        public function foo()
                                                echo 'foo';

class Users extends CI_Controller

                        public function index()
                                                foo(); // not work
                                                show_error('bar'); // works


foo() is a method of the MY_Exceptions class. You can't just call it like a procedural function. I'd suggest reading some more about object-orientated (OOP) PHP programming and how functions / methods / etc. work.

So, how can I call show_error() anywhere in CI_Controller/CI_Model ... ? If I remove show_error() in system/core/Exceptions.php, it will not work.

Because show_error() by itself is a procedural function inside of system/core/Common.php, which in turn calls the show_error() method of the Exceptions class.

Not 100% how it works, but as an example:

show_error(); // procedural

$exc = new Exceptions();
$exc->show_error(); // Object orientated class method.

Ah, great reference. Thanks a lot Aken.

Theme © iAndrew 2016 - Forum software by © MyBB