CodeIgniter Forums

Full Version: Indirect modification of overloaded property Template::$CI has no effect
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hey all,

I'm getting this error:

A PHP Error was encountered

Severity: Notice

Message: Indirect modification of overloaded property Template::$CI has no effect

Filename: libraries/Template.php

Line Number: 50

Fatal error: Cannot assign by reference to overloaded object

Basically in the Template library, which is autoloaded, I have a method called render_content:

function render_content($template = '', $view = '' , $data = array(), $return = FALSE){              
        $this->CI =& get_instance();
        $this->title = "Default Title";
        $this->subtitle = "Default Subtitle";
        $this->_data = array_merge($this->_data, $data);
        $this->set('yield', $this->CI->load->view($view, $_data, TRUE));            
        return $this->CI->load->view($template, $this->template_data, $return);

Basically, it sets a default title and subtitle and stores it into $_data array:

public function __set($name, $value){
        $this->_data[$name] = $value;

Then in controller I set some variables that override the defaults in Template:

public function signup(){
            $this->template->render_content('template', '/users/signup', array('title' => 'Signup Form', 'subtitle' => 'Free Case Evaluation'));

I think it has something to do with __set method, which overloads. But I don't know what else to do.

Thanks for response.

El Forum

You get this error from
$this->CI =& get_instance();

Apprearenly, $this->CI is an assigned reference, and since PHP 5.2, you can't assign something else by reference to it without first erasing it.

Instead, use
//test before assignment
$this->CI || $this->CI =& get_instance();

// or assign without reference (which is default)
$this->CI = get_instance();

// or unset the previous reference first
$this->CI = '';
$this->CI = get_instance();

// or use chaining

El Forum

Thanks for response. Your solution works.