iarp Posted September 15, 2011 Share Posted September 15, 2011 I'm trying to develop a Joomla plugin for 1.6/1.7 and from what I've read, future versions are supposed to be php E~STRICT compliant. I know that doesn't mean I have to fix this since it is just a notice, but I am curious how one would hide the error. $task_array = explode('.', JRequest::getVar('task')); # Splits article.save $task = $task_array[1]; #This is line 58 I know it happens because $task_array is empty, but how can i wrap that in something to stop this Notice error? I've tried !empty() but that doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/ Share on other sites More sharing options...
KevinM1 Posted September 15, 2011 Share Posted September 15, 2011 You need to use isset: $task_array = explode('.', JRequest::getVar('task')); if (isset($task_array) { $task = $task_array[1]; } EDIT: Keep in mind, the code above will only check if the entire array exists. If you need to check a particular element of the array, modify the if-conditional to reflect that. Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269434 Share on other sites More sharing options...
iarp Posted September 15, 2011 Author Share Posted September 15, 2011 Same issue, I believe that the JRequest::getVar('task') is always populated so the array will always be set at least 1 key. When i echo out [0] and [1] nothing prints but isset trips to true and it still produces the error. Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269436 Share on other sites More sharing options...
iarp Posted September 15, 2011 Author Share Posted September 15, 2011 Same issue, I believe that the JRequest::getVar('task') is always populated so the array will always be set at least 1 key. When i echo out [ 0 ] and [ 1 ] nothing prints but isset trips to true and it still produces the error. Stupid me hit Quote instead of Modify... Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269437 Share on other sites More sharing options...
KevinM1 Posted September 15, 2011 Share Posted September 15, 2011 Can you post a var_dump of your $task_array? Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269439 Share on other sites More sharing options...
iarp Posted September 15, 2011 Author Share Posted September 15, 2011 var_dump on $task_array is just "NULL" printed. var_dump on $task_array during event is string(14) "article.cancel" Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269444 Share on other sites More sharing options...
KevinM1 Posted September 15, 2011 Share Posted September 15, 2011 What is this 'event' and what does it have to do with your code? Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269447 Share on other sites More sharing options...
iarp Posted September 15, 2011 Author Share Posted September 15, 2011 When you click on something such as New, Edit, Cancel, Apply, Save...etc it directs you to a page with the task set to article.<event> and then redirects again to what ever it's supposed to do next. Such as clicking Save it gets article.save and then redirects back to the main article listing. I'm in the process of modifying old code to get it up to standards and I had hoped that I wouldn't have to dig through a ton of code to find all "save", "edit", "new" ...etc and replace them with "article.new" or "articles.publish". By catching this task var during the redirection event i could then split it on the period and use $task as the old system did saving myself a lot of work. But after a lot of deliberation with friends about this, I'm going to just update everything to standards instead of this shortcut, the proper way and be done with it for the future. Quote Link to comment https://forums.phpfreaks.com/topic/247163-notice-undefined-offset-1-line-58-error-produced-by-array-key-empty/#findComment-1269452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.