Undefined offset

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toshesh
Forum Commoner
Posts: 33
Joined: Thu Jun 19, 2003 9:32 pm

Undefined offset

Post by toshesh »

what does undefined offset mean??

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

$depth[$parser]++;
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :(
toshesh
Forum Commoner
Posts: 33
Joined: Thu Jun 19, 2003 9:32 pm

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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>
toshesh
Forum Commoner
Posts: 33
Joined: Thu Jun 19, 2003 9:32 pm

Post 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!
Post Reply