Undefined offset: 0 in - php

Don't know much about php, but I can figure somethings out and copy and paste.
My webhost seems to have updated php and code that worked for years now throws up errors. I had someone develop my php connection to a filemaker database and he is no longer available to help me with this problem:
The problem occurs in two places:
> Undefined offset: 0 in
this is the code:
$resultData = $Result['data'][$DataKeys[0]];
// and here:
$aRecID = preg_split('[.]',$DataKeys[0]);

It means $DataKeys[0] does not exist.
Try a var_dump on $DataKeys and simply take a look what is inside.
Use this small helper function, it generates a better output:
function pr($var) {
echo "<pre>";
var_dump($var);
echo "</pre>";
}

Related

Fatal error: Call-time pass-by-reference has been removed in /hsphere/local/home/aeldresa/tuc-management.dk/admin/system/functions.php on line 144

I have a problem that I need some help figuring out I have a Joomla site and after my host provider updated their php system I get the error Fatal error: Call-time pass-by-reference has been removed in /hsphere/local/home/aeldresa/tuc-management.dk/admin/system/functions.php on line 144
But when I look the problem up here anywhere on the internet people are saying that I just need to take away the & sign on line 144 but when I do that all hell brakes lose then I get a lot off errors like this one: Notice: Use of undefined /thefile
A image of the code
function xml_to_array ($data) {
$data = eregi_replace(">"."[[:space:]]+"."<","><",$data);
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($p, $data, &$vals, &$index);
xml_parser_free($p);
$i = 0;
$array = array();
$array[] = array(
'tag' => $vals[$i]['tag'],
'attributes' => decodearray ($vals[$i]['attributes']),
'value' => decodevalue($vals[$i]['value']),
'children' => GetChildren($vals, $i)
);
return $array;
}
I hope that there is someone can help me here :D
It's not about joomla but only php version. After php 5.3, the reference use changing.
Please look at this link : http://php.net/manual/en/language.references.pass.php
Note: There is no reference sign on a function call - only on function
definitions. Function definitions alone are enough to correctly pass
the argument by reference. As of PHP 5.3.0, you will get a warning
saying that "call-time pass-by-reference" is deprecated when you use &
in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was
removed, so using it will raise a fatal error.
You can see the same problem if you do something like that :
str_replace('', '', &$yourVar);
If your code is a joomla code, i suggest you to update your joomla version. If not, we need more information for help you (you need change your own code)
Good luck, coment and ask again if you need
You did fix the error when removing the & (we explained the process here: http://www.itoctopus.com/menu-item-manager-empty-in-joomla )
But, the errors that you are seeing are not really errors - they are just notices, and it's because the new version of PHP that you have installed has deprecated many functions and became stricter.
What you need to do is change the $error_reporting variable in your configuration.php file to -1 (I think right now it is set to something else), save it and then try again.
If you still see errors then you will need to fix them manually in the code (by just defining variables first, for example). Trust me, you probably only have a few errors (notices) but they are repeated many times, and that's why it looks like there are so many errors.
Hope this helps!

Can't pass a variable variable into a function in PHP since upgrading from 5.5.22 to 5.6.6?

This line of code worked perfectly before I upgraded, now it doesn't:
123: $thisRow[] = displayR(${"sR{$i}S1"}, ${"nR{$i}S1P"});
I get this error:
Undefined variable: sR1S1 in script.php on line 123
A workaround is to manually assign them first
$s = ${"sR{$i}S1"};
$n = ${"nR{$i}S1P"};
$thisRow[] = displayR($s, $n);
Is there anyway to get it working in a single line as before? Does anyone know why it no longer works?
I should add that I've tried using var_dump(${"sR{$i}S1"}); on the previous line and it IS defined, and has the value that I expect it to.
I can't find any mention of this behaviour on google or SO, I wonder if it's a bug rather than intended.
I believe this is to be an opcache bug.
Disabling opcache on the file in question resumed the expected behaviour.
I submitted a (fairly useless) bug report at:
https://bugs.php.net/bug.php?id=69159
Which has apparently been fixed and closed:
http://git.php.net/?p=php-src.git;a=commitdiff;h=a29b64fc1029b4121e3e9ff20901c35ad600b4da

Undefined Index Laravel 4.0 - Possible Bug?

I feel like I'm taking crazy pills here, so I hope I'm simply missing the obvious. Please find below exhibit a, my code including var_dumping:
$statuscheck = $read->readResponse();
$statusResponse = $statuscheck['StatusCheckResponse'];
echo "<pre>"; var_dump( $statuscheck, $statusResponse, $statuscheck['StatusCheckResponse']); die;
Which gives us the following results : Here be the results
That seems all normal right? Notice I've passed the $statuscheck['StatusCheckResponse'] into the $statusResponse var and var_dumped them both. Both giving identical results in the above output.
But watch what happens when I take the var_dump away.
This is what happens a giant undefined index error! How is this possible? What am I doing wrong?
If that code is inside a loop, or executed more than once on a single request, it could be a later iteration doesn't have the required indexes set.
Try replacing the die with this:
if(empty($statuscheck['StatusCheckResponse'])) die;

Undefined offset issue PHP

I have a variable $newExtract[$x][3]. When I try to explode it as:
explode("/", $newExtract[$x][3])
It gives me error message:
"Notice: Undefined offset: 3 in C:\xampp\htdocs\torrent\classes\sm9.class.php on line 63".
But, when I echo it using echo $newExtract[$x][3]; die();, it gives me the result as 13/08/2012 20:58.
Can anyone help me what is happening? Why, I am not able to explode it?
Thanks
I've seen several places in PHP where implicit string conversion (or string dereferencing, in this case) causes issues and the simplest path to sanity is using an intermediate variable:
$date = $newExtract[$x][3];
explode("/", $date);
It seems to show up more often with certain internal functions, and I usually run into it more with objects and __toString(), but this wouldn't be the first time for this situation, either.

Undefined variable Issue Between Different PHP Version?

I am using XAMPP 1.7.2 (PHP 5.3) to devlope on winxp localhost.
There is a function works quite well. Comes from CodeIgniter Module.
function get_cal_eventTitle($year, $month){
$this->db->where('eventYear =', $year);
$this->db->where('eventMonth =', $month);
$this->db->select('eventTitle');
$query = $this->db->get('tb_event_calendar');
$result = $query->result();
foreach ($result as $row)
{
$withEmptyTitle = $row->eventTitle;
//echo $withEmptyTitle.'<br>';
$noEmptyTitle = str_replace(" ","%20",$withEmptyTitle);
$withUrlTitle = '<a href='.base_url().'index.php/calendar/singleEvent/'.$year.'/'.$month.'/'.$noEmptyTitle.'/'.'>'.$withEmptyTitle.'</a>';
//echo $withUrlTitle.'<br>';
$row->eventTitle = $withUrlTitle;
}
return $result;
}
When I upload my code to remote server(PHP 5.2.9). It show error as this,
withEmptyTitle undefined variable
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: withUrlTitle
Filename: models/calendar_model.php
Line Number: 54 // $withEmptyTitle = $row->eventTitle;
But When I enable the comment for the line echo $withEmptyTitle.'<br>';. It works well on remote server.
Assuming withEmptyTitle echo to Apr running event here.
I don't know why? Could you give me some suggestion to fix this issue? Appreciated for your input.
What you're seeing is probably not an error, but a warning.
PHP may be throwing the warning because you're using a variable that hasn't been initialised. It sounds likely that your local development PHP installation has warning messages supressed, whereas your live server has them enabled. (In fact, best practice would be to have it the other way round!)
In this case, it's possible that $withEmptyTitle = $row->eventTitle; is not initialising the $withEmptyTitle variable, if the eventTitle property is returning as unset. It would then fall following line and throw the warning when you try to use the variable in the str_replace() call.
You could avoid this warning by:
Switching warning message off in the PHP.ini
Doing ini_set() to switch it off during the program.
using isset($withEmptyTitle) to check that the variable is set prior to actually using it.
Ensuring that $row does actually contain an eventTitle property (in the context of your program, if it's missing, it may imply bad data or incorrect database table setup? In any case, you could change the SQL query to use IFNULL() or at least ensure the field is explicitly queried.
[EDIT]
I see you've edited the question. In particular, I note the following:
Line Number: 54 // $withEmptyTitle = $row->eventTitle;
I note the // .... does that imply that the line is commented out?? Have you somehow got a copy on the server which has that line commented? That would certainly explain the fact that you're getting warnings!

Categories