Welcome Guest, Not a member yet? Register   Sign In
Undefined constant CodeIgniter\Router\Router::HTTP_METHODS
#1

Hi guys,

Can someone tell me what this error means? I can see the constant is defined in Router.php.

Code:
CRITICAL - 2024-06-25 16:30:02 --> Error: Undefined constant CodeIgniter\Router\Router::HTTP_METHODS
in SYSTEMPATH\Router\DefinedRouteCollector.php on line 35.
1 SYSTEMPATH\Debug\Toolbar\Collectors\Routes.php(105): CodeIgniter\Router\DefinedRouteCollector->collect()
2 SYSTEMPATH\Debug\Toolbar\Collectors\BaseCollector.php(226): CodeIgniter\Debug\Toolbar\Collectors\Routes->display()
3 SYSTEMPATH\Debug\Toolbar.php(93): CodeIgniter\Debug\Toolbar\Collectors\BaseCollector->getAsArray()
4 SYSTEMPATH\Debug\Toolbar.php(370): CodeIgniter\Debug\Toolbar->run(1719304186.26961, 16.1719, Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response))
5 SYSTEMPATH\Filters\DebugToolbar.php(43): CodeIgniter\Debug\Toolbar->prepare(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response))
6 SYSTEMPATH\Filters\Filters.php(211): CodeIgniter\Filters\DebugToolbar->after(Object(CodeIgniter\HTTP\IncomingRequest), Object(CodeIgniter\HTTP\Response), null)
7 SYSTEMPATH\CodeIgniter.php(522): CodeIgniter\Filters\Filters->run('update/install', 'after')
8 SYSTEMPATH\CodeIgniter.php(361): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
9 FCPATH\index.php(79): CodeIgniter\CodeIgniter->run()

PHP Code:
class Router implements RouterInterface
{
    /**
    * List of allowed HTTP methods (and CLI for command line use).
    */
    public const HTTP_METHODS = [
        Method::GET,
        Method::HEAD,
        Method::POST,
        Method::PATCH,
        Method::PUT,
        Method::DELETE,
        Method::OPTIONS,
        Method::TRACE,
        Method::CONNECT,
        'CLI',
    ]; 
Reply
#2

According to the PHP Manual:

class constant are by default public in nature but they cannot be assigned visibility factor and in turn gives syntax error.


PHP Code:
<?php

class constants {

    const MAX_VALUE 10;
        public const MIN_VALUE =1;

}

// This will work
echo constants::MAX_VALUE;

// This will return syntax error 
echo constants::MIN_VALUE
?>
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Thanks, so is this a bug in the CI framework then?
Reply
#4

(This post was last modified: 06-25-2024, 11:04 PM by kenjis.)

No.

Quote:Note:
As of PHP 7.1.0 visibility modifiers are allowed for class constants.
https://www.php.net/manual/en/language.o...stants.php

See https://3v4l.org/o7LIW
Reply
#5

Testing my code with CI_ENVIRONMENT = production, works fine.

But on development, a critical error is thrown. Looks like something related to the debug toolbar. I've no idea to where to look, suggestions welcome.
 
Code:
CRITICAL - 2024-06-25 16:30:02 --> Error: Undefined constant CodeIgniter\Router\Router::HTTP_METHODS
in SYSTEMPATH\Router\DefinedRouteCollector.php on line 35.
Reply
#6

If the constant HTTP_METHODS is defined in CodeIgniter\Router\Router, I have no idea why the error occurs.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB