How to redefine a constructor in php?

1

my question is simple, how do I redefine the constructor of the parent class, with different behavior?

What I want to do is inherit from the Exceptional class of php (that its constructor prints the exception on screen), and redefine that constructor so that it does not show anything.

<?php 

    class Excepcion404 extends Exception{

        public function __construct() {
            //Este metodo muestra una vista 
            Vista::crear(GENERAL_BUNDLE."views/index.php");

        }
    }

When I do:

throw new Excepcion404();

The result I get is that it shows me the view, but below all this:

Fatal error: Uncaught Excepcion404 in C:\xampp\htdocs\Neomix\controladorFrontal\ruta.php:64 
Stack trace: 
    #0 C:\xampp\htdocs\Neomix\controladorFrontal\ruta.php(18): Ruta->buscarEnElArray('/dafasdwdaw') 
    #1 C:\xampp\htdocs\Neomix\controladorFrontal\ruta.php(8): Ruta->submit() 
    #2 C:\xampp\htdocs\Neomix\rutas\rutas.php(7): Ruta->controladores(Array) 
    #3 C:\xampp\htdocs\Neomix\controladorFrontal\core.php(29): include('C:\xampp\htdocs...') 
    #4 C:\xampp\htdocs\Neomix\index.php(6): include('C:\xampp\htdocs...') 
    #5 {main} thrown in C:\xampp\htdocs\Neomix\controladorFrontal\ruta.php on line 64

I would like you to just show me the view and not to print that horrible mistake.

ADDED:

I'm building my own framework, when I capture the URI what I do is call a function that looks in an array, if that URI exists in my web, in case of finding it, it returns the driver that I will use and the method :

...código...
$respuesta = ruta.buscarEnElArray($urlCapturada);
...código...

and my role does the following:

public function buscarEnElArray($rutaABuscar){
            foreach ($this->_controladores as $url => $controladorYmetodo) {
                if($url == $rutaABuscar){
                    return $controladorYmetodo;
                }
            }

            throw new Excepcion404();

        }

Of course, thank you very much!

    
asked by cortigeronimo 05.04.2017 в 14:55
source

1 answer

0

There is no point in creating an exception that does not throw an exception. It goes against the concept of exception.

The Excepcion404 is a good idea, but that's not where you have to show the view.

The code to show the view you have to put in the section catch of a try .

    
answered by 05.04.2017 / 19:14
source