Need help in resolving "Illegal String Offset" warning messa

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joinnavdev
Forum Newbie
Posts: 21
Joined: Thu Feb 05, 2015 2:34 pm

Need help in resolving "Illegal String Offset" warning messa

Post by joinnavdev »

Actually I am moving the HRMS application from older to latest version of PHP but I am getting the below warnings.
Appreciate help or any suggestions to resolve the issue......

***** Please use PHP Code tag *****

Code: Select all

foreach($result1 as $resultset1)
    {
 $stringData3="<li><a href=\"##LBL_SITE_URL##index.php/".$resultset['module_value']."/".$resultset1['features_value']."\">";          
 $stringData4=$stringData3.$resultset1['features_name']."</a></li>";		   
 fwrite($fh,$stringData4);
    }
Error:
Warning: Illegal string offset 'features_value'

Warning: Illegal string offset 'features_name'
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help in resolving "Illegal String Offset" warning m

Post by Christopher »

There is a value assigned to $resultset['module_value'], but no values are assigned to $resultset1['features_value'] or $resultset1['features_name'].
(#10850)
joinnavdev
Forum Newbie
Posts: 21
Joined: Thu Feb 05, 2015 2:34 pm

Re: Need help in resolving "Illegal String Offset" warning m

Post by joinnavdev »

Hi Christopher,

Thanks for looking into the post & responding it to resolve the issue.

I am actually layman to PHP, appreciate if you can help me out with changes to the code, as I tried with ISSET but couldn't get rid of the warnings.

Will look forward for your help.

Thanks,
Nick
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help in resolving "Illegal String Offset" warning m

Post by Christopher »

You have a couple of choices. The best would be to make sure that the $result1 array had all the array elements that are needed -- before you get to this loop.

You an also do the checks in this loop.

Code: Select all

foreach($result1 as $resultset1)
    {
 $stringData3="<li><a href=\"##LBL_SITE_URL##index.php/".$resultset['module_value']."/".(isset($resultset1['features_value'])?$resultset1['features_value']:'')."\">";          
 $stringData4=$stringData3.(isset($resultset1['features_name'])?$resultset1['features_name']:'')."</a></li>";		   
 fwrite($fh,$stringData4);
    }
It might be better to have features_value default to 0 or -1 instead of '' so you can check the value you receive from this URL. Likewise features_name default would be clearer as 'N/A' or 'NO NAME'.
(#10850)
Post Reply