View Full Version : Illegal string offset Error - Any ideas?
kronnos
05-11-2013, 09:38 PM
Anyone have any idea what this error could mean on top of the page?
Warning: Illegal string offset 'ds' in [path]/awcoding/plugins/awc.php on line 296
Its showing up for only on top of threads that have a donation award image under username in their post.
Here is what line 296-300 of the awc.php looks like:
if ( $awc_goal['extra'] == 2 ){
print_description_row( $vbphrase['awc_goal_extra_2'], 0, 2, 'thead', $stylevar['left'] );
} else {
print_yes_no_row( $vbphrase['awc_goal_extra'], 'extra_'.$awc_goal['id'], $awc_goal['extra'] );
}
I doubt I would get any help from the mod developer since its in the graveyard but i would atleast want to figure out a temp fix untill I chnage to something else.
BTW - I think this started to happen after I updated server to latest php version 5.4.
Thanks!
I think that error happens when you have code like $somevar['ds'] and $somevar is a string. You can have something like $somevar[4] to get the 4th char in the string, but IIRC before 5.4 using a string would just default to 0, and now it generates a warning.
But I don't see any 'ds' being used in square brackets, so I don't see what's causing it.
tbworld
05-11-2013, 10:57 PM
IIRC
IIRC <--- "If I recall correctly"
Okay "kh99" stop making me feel old. I had to look this one up. :)
IIRC <--- "If I recall correctly"
Okay "kh99" stop making me feel old. I had to look this one up. :)
lol, it's likely I'm as old as you are. But I think those abbreviations aren't technically allowed in this forum, so I'm not setting a very good example. Edit: but I don't see it in the rules, so it's OK, I guess I'm thinking of a different forum.
kronnos
05-12-2013, 12:47 AM
Thanks. i didnt know much what to do with that so i went looking for the ['ds'] in the file elsewhere but could not find anything. I even tried changing "if ( $awc_goal['extra'] == 2 )" to "if ( $awc_goal[0] == 2 )" and doing a bunch of other weird things to see how it impacts anything but didnt really chnage. I even deleted the entire first If statement and it kept giving me the same error at the start of the second if statement.
Maybe its something at the end of the if statements having to do with "$lastid = $awc_goal['id']; and $lastsid = $awc_goal['sid'];" ?
If there is no obvous answer, is there a way to just turn of erro reporting for that specific page? Second option would be to completely disable the mod but it works fine for what I need until I can migrate.
Thanks!
if ( $awc_goal['extra'] == 2 ){
print_description_row( $vbphrase['awc_goal_extra_2'], 0, 2, 'thead', $stylevar['left'] );
} else {
print_yes_no_row( $vbphrase['awc_goal_extra'], 'extra_'.$awc_goal['id'], $awc_goal['extra'] );
}
print_yes_no_row( $vbphrase['awc_goal_erenew'], 'erenew_'.$awc_goal['id'], $awc_goal['erenew'] );
print_yes_no_row( $vbphrase['awc_goal_edisplay'], 'edisplay_'.$awc_goal['id'], $awc_goal['edisplay'] );
print_input_row( $vbphrase['awc_goal_tag'], 'tag_'.$awc_goal['id'], $awc_goal['tag'] );
print_input_row( $vbphrase['awc_goal_ord'], 'ord_'.$awc_goal['id'], $awc_goal['ord'] );
if ( $awc_goal['id'] != $lastid ){
echo '<tbody>';
print_description_row( "<input type=\"submit\" class=\"button\" value=\" $vbphrase[save] \" tabindex=\"1\" title=\"".$vbphrase['save_settings']."\" />", 0, 2, 'tfoot" style="padding:1px" align="right' );
echo '</tbody>';
print_table_break();
}
$lastid = $awc_goal['id'];
$lastsid = $awc_goal['sid'];
} else {
print_stop_message( 'awc_no_access' );
}
}
print_submit_row( $vbphrase['save'] );
darnoldy
05-12-2013, 12:49 AM
But I think those abbreviations aren't technically allowed in this forum, so I'm not setting a very good example.IM(NS)HO, us old guys should take pride in our abbreviations! LMAO
--don
tbworld
05-12-2013, 03:20 AM
Your problem is in reference to this change in php.
Non-numeric string offsets - e.g. $a['foo'] where $a is a string - now return false on isset() and true on empty(), and produce a E_WARNING if you try to use them. Offsets of types double, bool and null produce a E_NOTICE. Numeric strings (e.g. $a['2']) still work as before. Note that offsets like '12.3' and '5 foobar' are considered non-numeric and produce a E_WARNING, but are converted to 12 and 5 respectively, for backward compatibility reasons. Note: Following code returns different result. $str='abc';var_dump(isset($str['x'])); // false for PHP 5.4 or later, but true for 5.3 or less
http://us1.php.net/manual/en/migration54.incompatible.php
I could be more helpful if I knew where your code was derived from. I troubleshoot this type of problem by using zend/xdebug and var_dump the variables that are in play. Most likely a non-numeric number is being used as an offset. Anyway just my guess :)
kronnos
05-12-2013, 03:28 AM
So do you mean if I change for example
if ( $awc_goal['extra'] == 2 )
To a numeric like:
if ( $awc_goal[2] == 2 )
There should not be an error?
Or would I need to go deeper and find out where the variable 'extra' is defined and change it in there? Ill see if I could play with any of that..
Thanks!
tbworld
05-12-2013, 03:57 AM
So do you mean if I change for example
if ( $awc_goal['extra'] == 2 )
Set a var_dump on: var_dump($awc_goal['extra']);
It may not display any useful information without collecting the data for analysis, but take it one step at a time.
What tools do you have at your disposal for debugging? I can help you better if I know your limitations. We all have them :)
kronnos
05-12-2013, 04:06 AM
Sorry, not sure how to set a var dump..
Found this online:
function grab_dump($var)
{
ob_start();
var_dump($var);
return ob_get_clean();
}
so would my function look like:
{
ob_start();
var_dump($awc_goal['extra']);
return ob_get_clean();
}
If so , do I just add that to the php and hope for the var to show up on the screen? :)
tbworld
05-12-2013, 04:33 AM
I believe your code warning is about line 295. So edit that file and on line 294 put. var_dump($awc_goal['extra']); die(__FILE__.__LINE__);
This will display to the screen then php will die.
This may not give us the any useful data as the error may not have occurred as of yet. In fact it probably did not, but lets see what it says first.
The buffered var_dump code you found is important ... but hold off. Maybe you will get lucky.
Then try moving die to the end of loop so that you display more data. The data may end up being positioned all over your screen. Normally we write this data to an external file or an array.
Thanks. i didnt know much what to do with that so i went looking for the ['ds'] in the file elsewhere but could not find anything. I even tried changing "if ( $awc_goal['extra'] == 2 )" to "if ( $awc_goal[0] == 2 )" and doing a bunch of other weird things to see how it impacts anything but didnt really chnage. I even deleted the entire first If statement and it kept giving me the same error at the start of the second if statement.
I think another possibility is something like $somevar[$someothervar]. I don't see that anywhere around line 296, but maybe the line number is wrong for some reason. (The string 'ds' does appear in a number of places, so it is a string that's being used in that code).
You could try putting
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
at the top of the file.
kapii
05-12-2013, 10:15 AM
TBH I would just stop using that mod and switch to this one, https://vborg.vbsupport.ru/showthread.php?t=287053
It is fully supported and is pretty cool.
EDIT: Nevermind I just realized this is vB3 that mod is vB4 only, sorry.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.