Page 1 of 1

Undefined offset

Posted: Thu Jun 26, 2003 3:41 am
by toshesh
what does undefined offset mean??

it's on the line below. (part of an xml parser)

$depth[$parser]++;

Posted: Thu Jun 26, 2003 5:38 am
by volka
usually that you try to access an key/element that does not exist within the array

Code: Select all

$arr = array('a'=>'A', 'b'=>'B');
echo $arr['z'];
in your case it's probably because of

Code: Select all

class MyClass
{
 // fill me with something useful if you must
}

$obj = new MyClass;
$dh = opendir('.');
$parser = xml_parser_create();

$arr = array($obj=>"doesn't work", $dh=>'this neither', $parser=>'bad luck again');
print_r($arr);
sorry :(

Posted: Thu Jun 26, 2003 8:27 pm
by toshesh
I dont really understand what you mean sorry...

I guess the value is basically outside the array range right? If the code line comes out as undefined offset does the line get executed or gets omitted completely?

Posted: Fri Jun 27, 2003 3:02 am
by volka
of what type is $parser?
The example above only states that ressources and objects cannot be used as array-keys (yet?)

if the key can be used, the line will be executed as you can test with

Code: Select all

<html><body>
<pre><?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$arr = array();
$arr[0]++;
print_r($arr);
?></pre>
</body></html>

Posted: Fri Jun 27, 2003 5:37 am
by toshesh
it was part of an xml parser i found on the net. I removed it and nothing happened so problem solved? thank you for helping me!