Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot extend core HTTPException class #3178

Closed
arnisjuraga opened this issue Jun 28, 2020 · 2 comments
Closed

Cannot extend core HTTPException class #3178

arnisjuraga opened this issue Jun 28, 2020 · 2 comments

Comments

@arnisjuraga
Copy link

What I am trying to do is to extend core HTTPException class because Facebook API on HTTP requests replies with non-standart HTTP response codes and Codeigniter throws Exception on those cases.
So, I wanted to extend HTTPException class to add additional non-standart HTTP response codes (like 190 from https://developers.facebook.com/docs/graph-api/using-graph-api/error-handling/#errorcodes )

The documentation states that, e.g.:

If you need to use a constructor in your class make sure you extend the parent constructor:

https://codeigniter4.github.io/CodeIgniter4/extending/core_classes.html#extending-core-classes

My app/Config/Autload.php config line for additional class loading:

$classmap = [
            'CodeIgniter\HTTP\Exceptions\HTTPException' => APPPATH . '/HTTPException.php',
        ];

And the class file itself located under app/HTTPException.php:

<?php

use CodeIgniter\HTTP\Exceptions\HTTPException;

class HTTPException extends \CodeIgniter\HTTP\Exceptions\HTTPException
{
    public function __construct()
    {
        dd("Loaded!"); 
    }
}

My example looks like this, but it always throws some error that
Fatal error: Cannot declare class HTTPException because the name is already in use in /app/HTTPException.php on line 7

Similar questions:

And, also, it would be enough if those codes would be possible to "ignore"?
Like problem described here: https://forum.codeigniter.com/thread-75069.html
And the extension of core classes also discussed here: #358

@paulbalandan
Copy link
Member

The name of the child class clashes with the parent class. So, perhaps, you can change the name of the core HTTPException in your use statement.

use CodeIgniter\HTTP\Exceptions\HTTPException as BaseHTTPException;

class HTTPException extends BaseHTTPException
{

}

@michalsn
Copy link
Member

Please use our forum for support questions. This place is for bug reporting only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants