codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.39k stars 1.9k forks source link

Bug: Uncaught ErrorException: print_r(): Property access is not allowed yet #6376

Closed fre2mansur closed 2 years ago

fre2mansur commented 2 years ago

PHP Version

7.3

CodeIgniter4 Version

4.1.9

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

mysql

What happened?

I was trying to test the custom DB connections, I want to handle the invalid DB connection but it's throwing me the below message.

ErrorException #1
Uncaught ErrorException: print_r(): Property access is not allowed yet in 
APPPATH\Views\errors\html\error_exception.php at line 96

Steps to Reproduce

My Connection Model

 protected $beforeInsert   = ['testConnection'];

    protected function testConnection(array $data)
    {
        $custom = [
            'DSN'      => '',
            'hostname' => $data['data']['host'],
            'username' => $data['data']['username'],
            'password' => $data['data']['password'],
            'database' => '',
            'DBDriver' => 'MySQLi',
            'DBPrefix' => '',
            'pConnect' => false,
            'DBDebug'  => (ENVIRONMENT !== 'production'),
            'charset'  => 'utf8',
            'DBCollat' => 'utf8_general_ci',
            'swapPre'  => '',
            'encrypt'  => false,
            'compress' => false,
            'strictOn' => false,
            'failover' => [],
            'port'     => $data['data']['port'],
        ];

        try {
            $forge = \Config\Database::forge($custom);
            $forge->createDatabase('my_db_2');  //breaks here
        }  catch(\Exception $e) {
           exit($e->getMessage()); //it supposed to break here
        }
        die();
        return $data;
    }

Expected Output

To handle the error on catch mode

Anything else?

I'm not sure if is this bug or if am i missing something.

image

kenjis commented 2 years ago

First, upgrade to the latest version. https://github.com/codeigniter4/CodeIgniter4/releases

Please ask your support questions in the forums. Thanks! https://forum.codeigniter.com/forum-30.html

If you are not sure whether you are using something correctly or if you have found a bug, again - please ask on the forums first. https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/bug_report.md#support