Jump to content

Notice: Undefined offset: 1 line 58 - error produced by array key empty.


iarp

Recommended Posts

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.

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.

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.

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...

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.