Page 1 of 1

Need help in resolving "Illegal String Offset" warning messa

Posted: Thu Feb 05, 2015 2:38 pm
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'

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

Posted: Thu Feb 05, 2015 4:11 pm
by Christopher
There is a value assigned to $resultset['module_value'], but no values are assigned to $resultset1['features_value'] or $resultset1['features_name'].

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

Posted: Thu Feb 05, 2015 11:01 pm
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

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

Posted: Fri Feb 06, 2015 3:39 pm
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'.