1127

Uncaught TypeError

Comments for “Uncaught TypeError”
 

Posted by Balazs on Monday 17th April 2023 at 23:33 GMT

I used the Trongate Desktop App (v1.0.004) to create a new app.
On the default "IT TOTALLY WORKS!" page I get the following error:

Fatal error: Uncaught TypeError: Trongate::load_view_file(): Return value must be of type ?string, none returned in C:\xampp\htdocs\my_new_app\engine\Trongate.php:112 Stack trace: #0 C:\xampp\htdocs\my_new_app\engine\Trongate.php(94): Trongate->load_view_file('C:/xampp/htdocs...', Array, false) #1 C:\xampp\htdocs\my_new_app\modules\welcome\controllers\Welcome.php(5): Trongate->view('welcome') #2 C:\xampp\htdocs\my_new_app\engine\Core.php(217): Welcome->index('') #3 C:\xampp\htdocs\my_new_app\engine\Core.php(13): Core->serve_controller() #4 C:\xampp\htdocs\my_new_app\public\index.php(5): Core->__construct() #5 {main} thrown in C:\xampp\htdocs\my_new_app\engine\Trongate.php on line 112


Is it related to the new "type hinting and return types" update? What's the fix?
Level One Member

Balazs

User Level: Level One Member

Date Joined: 8/04/2023

Posted by DaFa on Tuesday 18th April 2023 at 10:43 GMT

I'd say yes it probably is the new type hinting DC introduced a few days back. I'd also guess you are using PHP 8.2 or 8.1.17 as well.

I'll look at this a bit later tonight when I'm in front of my laptop.

**** UPDATE
I've created a pull request that fixes these errors - DC will look at them and review them later.

These are the fixes to Trongate.php
protected function view(string $view, array $data = [], bool $return_as_str = false): string|null {
        if ($this->parent_module !== '' && $this->child_module !== '') {
            // Load view from child module
            $output = $this->load_view_file($view, $data, $return_as_str);
            if ($return_as_str) {
                return $output;
            }
        } else {
            // Normal view loading process
            $module_name = $data['view_module'] ?? $this->module_name;
            extract($data);
            $view_path = APPPATH . 'modules/' . $module_name . '/views/' . $view . '.php';
            if (!file_exists($view_path)) {
                $view = str_replace('/', '/views/', $view);
                $view_path = APPPATH . 'modules/' . $view . '.php';
            }
            $output = $this->load_view_file($view_path, $data, $return_as_str);
            if ($return_as_str) {
                return $output;
            }
        }
        return null;
    }

    protected function load_view_file(string $view_path, array $data, bool $return_as_str): string|null|false {
        if (!file_exists($view_path)) {
            throw new Exception('View ' . $view_path . ' does not exist');
        }
        if ($return_as_str) {
            ob_start();
            require $view_path;
            return ob_get_clean() ?: null;
        } else {
            require $view_path;
            return false;
        }
    }

This comment was edited by DaFa on Tuesday 18th April 2023 at 13:44 GMT

Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Balazs on Tuesday 18th April 2023 at 16:17 GMT

Yes, I use PHP 8.2. Thank you for the quick response.
Level One Member

Balazs

User Level: Level One Member

Date Joined: 8/04/2023

×