Codeigniter Datamapper ORM php 7 static issue
Asked Answered
B

3

5

When I upgraded my server to php7 codeigniter and in particular datamapper ORM gives me this error...

Message: Accessing static property DataMapper::$config as non static
Filename: libraries/datamapper.php Line Number: 6474

the function in question is...

protected function _dmz_assign_libraries()
{
    static $CI;
    if ($CI || $CI =& get_instance())
    {
        // make sure these exists to not trip __get()
        $this->load = NULL;
        $this->config = NULL;
        $this->lang = NULL;
        // access to the loader
        $this->load =& $CI->load;
        // to the config
        $this->config =& $CI->config;
        // and the language class
        $this->lang =& $CI->lang;
    }
}
Badderlocks answered 12/6, 2017 at 2:29 Comment(0)
S
8

I have the same problem. To fix it, try to add new protected static method

protected static function get_config_object() {
    $CI =& get_instance();

    return $CI->config;
}

then delete or comment the lines 6474 and 6481 (in _dmz_assign_libraries, where values are assigned to $this->config),

and finally replace all calls $this->config with self::get_config_object()

It should run correctly now.

Sheik answered 19/7, 2017 at 18:14 Comment(0)
F
3

Try to suppress error with @, eg:

@$this->config =& $CI->config;
Fiver answered 12/2, 2018 at 16:28 Comment(0)
C
0

I faced the same problem.

FIX: Replace the actual datamapper.php library version with the latest one.

As mentioned in the official library website

Latest library version (1.8.3-dev) - source: https://github.com/saekort/datamapper/blob/master/application/libraries/datamapper.php

Cartesian answered 11/2, 2021 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.