I have written a custom add-on which consists of an extension and a plugin.
The extension basically loops through a set of channel entries, gets some matrix data and performs a calculation based on the contents of a grid field and then stores that information within the the entry. This all works great.
The plugin uses the calculation method of the extension and works OK except for one critical element.
The extension features a setting for a "multiplier value" which it uses in its calculation. Everything appears to be fine with this and if I change the value in the extension's settings the resulting figures are correct.
However, the plugin displays a PHP Warning about an Illegal string offset for this multiplier setting. If I hardcode the setting within the extension or remove that part of the calculation then again it works OK.
The problem seems to be the way the extension accesses the setting value. I'm guessing that when used internally it manages to muddle through and works but is fundamentally done incorrectly.
I've got the following within my extension;
function settings() {
$settings = array();
$settings['points_multiplier'] = array('i', '', "1"); // default value is 1
return $settings;
} // END
And the method that does the calculation returns a value multiplied by that setting...
// use points multiplier (default is 1)
$points_multiplier = $this->settings['points_multiplier'];
$total_credits = $total_credits * $points_multiplier;
return $total_credits;
If I dump out the value of $points_multiplier or $this->settings['points_multiplier'] then I get the value expected (although the latter outputs a string).
As far as I can tell, I've done the settings bit correctly.
So why does my plugin throw this warning and ultimately not work?
UPDATE Rob Sanchez's answer fixed the problem but for the sake of completeness, here is the code that I was using in my plugin.
$ext = new Fm_credits_from_entry_ext();
$query = $this->EE->db->select('entry_id')->where('author_id',$this->author_id)->where('channel_id','7')->where('status',$status)->get('channel_titles');
if($query->num_rows() > 0){
foreach($query->result_array() as $row){
$credits += $ext->calculate_total_credits($row['entry_id']);
}
}
The missing nugget of information was that when the extension is loaded by the plugin it is necessary to manually load the settings for that extension.