Codeigniter: Fatal error: Class 'stdclass' not found in mysqli_result.php on line 183

Created on 3 Mar 2017  路  2Comments  路  Source: bcit-ci/CodeIgniter

I got this error from CI.

Environment
IIS 10
PHP 7.0.16

I solved this problem changing the line 183 of mysqli_result.php to

protected function _fetch_object($class_name = '\stdClass')

Most helpful comment

Please explain how you managed to trigger this first.

There's at least 2 reasons why it doesn't make sense:

  • A string class name is always interpreted as an absolute (i.e. namespaces included) class path by PHP. In other words, the leading namespace separator is assumed/irrelevant for string class names (as well as in use statements). If this is somehow not the case in some MySQLi function - then it would be a PHP bug.
    This is easily testable:

    $ php -r "namespace Dummy { var_dump(class_exists('stdClass')); }"
    Command line code:1:
    bool(true)
  • CI_DB_mysqli_result is not declared inside a namespace. Thus, even if the former point wasn't true, 'stdClass' would still resolve to \stdClass when relatively searched for, as both classes reside in the root namespace.

Also, linking #5043.

All 2 comments

nice

Please explain how you managed to trigger this first.

There's at least 2 reasons why it doesn't make sense:

  • A string class name is always interpreted as an absolute (i.e. namespaces included) class path by PHP. In other words, the leading namespace separator is assumed/irrelevant for string class names (as well as in use statements). If this is somehow not the case in some MySQLi function - then it would be a PHP bug.
    This is easily testable:

    $ php -r "namespace Dummy { var_dump(class_exists('stdClass')); }"
    Command line code:1:
    bool(true)
  • CI_DB_mysqli_result is not declared inside a namespace. Thus, even if the former point wasn't true, 'stdClass' would still resolve to \stdClass when relatively searched for, as both classes reside in the root namespace.

Also, linking #5043.

Was this page helpful?
0 / 5 - 0 ratings