UserApplePie / UserApplePie-v4

UserApplePie v4 User Management System MVC Framework CMS PHP MySQL
https://www.userapplepie.com
16 stars 7 forks source link

AdminPanel-SystemRoutes crash. #68

Closed EddyBeaupre closed 6 years ago

EddyBeaupre commented 6 years ago

When trying to access the System Routes admin pannel on a brand new installation, you get the following error:

There is an error on this page.
Error has been logged and Admin has been notified. Please try again later.

Home

errors/php-error.log report the following:

2018-04-12 17:55PM - Invalid argument supplied for foreach() in /var/www/.../app/Controllers/AdminPanel.php on line 781

Apache doesn't log any other errors.

davarravad commented 6 years ago

I am aware of this issue and will be pushing a fix with the new update soon.

As PHP progresses in versions we have to take extra steps to prevent these errors.

What is your server's setup? OS, Apache, PHP, version etc...

The code related to this error is as follows:

        /** Check the following Directory for classes and methods **/
        $directory = APPDIR.'Controllers';
        $scanned_directory = array_diff(scandir($directory), array('..', '.'));

        /** Extract the methods from the classes **/
        foreach ($scanned_directory as $filename) {
            /** Remove the .php from the files names to get Class Names **/
            $class = str_replace('.php', '', str_replace('-', ' ', $filename));
            /** Get array of class methods **/
            $class_methods = get_class_methods('App\\Controllers\\'.$class);
            /** Remove blank and __construct methods from array **/
            if($class_methods[0] == ""){
                unset($class_methods[0]);
            }
            if($class_methods[0] == "__construct"){
                unset($class_methods[0]);
            }
            if($class_methods[1] == "__construct"){
                unset($class_methods[1]);
            }

            foreach ($class_methods as $method) {
                if(checkCoreRoutes($class, $method)){
                    $routes[] = array(
                        "controller" => $class,
                        "method" => $method
                    );
                }
            }
        }

Try the following and let me know what the result is:

        /** Check the following Directory for classes and methods **/
        $directory = APPDIR.'Controllers';
        $scanned_directory = array_diff(scandir($directory), array('..', '.'));

        /** Extract the methods from the classes **/
        if(isset($scanned_directory)){
            foreach ($scanned_directory as $filename) {
                /** Remove the .php from the files names to get Class Names **/
                $class = str_replace('.php', '', str_replace('-', ' ', $filename));
                /** Get array of class methods **/
                $class_methods = get_class_methods('App\\Controllers\\'.$class);
                /** Remove blank and __construct methods from array **/
                if($class_methods[0] == ""){
                    unset($class_methods[0]);
                }
                if($class_methods[0] == "__construct"){
                    unset($class_methods[0]);
                }
                if($class_methods[1] == "__construct"){
                    unset($class_methods[1]);
                }

                foreach ($class_methods as $method) {
                    if(checkCoreRoutes($class, $method)){
                        $routes[] = array(
                            "controller" => $class,
                            "method" => $method
                        );
                    }
                }
            }
        }
EddyBeaupre commented 6 years ago

Ubuntu 16.04.4 LTS Apache/2.4.18 (Ubuntu) PHP 7.0.28-0ubuntu0.16.04.1

For an unknown reason it work not and i didn't change anything to the setup.... Weird