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

[eluser]xander9x[/eluser]
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.

Code:
class MY_Exceptions extends CI_Exceptions
{

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

                        public function foo()
                        {
                                                echo 'foo';
                        }


Code:
class Users extends CI_Controller
{

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

Thanks!
#2

[eluser]Aken[/eluser]
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.
#3

[eluser]xander9x[/eluser]
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.
#4

[eluser]Aken[/eluser]
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:

Code:
show_error(); // procedural

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

[eluser]xander9x[/eluser]
Ah, great reference. Thanks a lot Aken.




Theme © iAndrew 2016 - Forum software by © MyBB