0

I keep getting an error when I try to instantiate the ArrayIterator class within a name space

$a = new ArrayIterator;

//works just fine

namespace test;

$a = new ArrayIterator;

//get error
//Fatal error: Class 'test\ArrayIterator' not found in /www/ on line 3

I've been searching the web for hours now and I still can't find a solution to solve this problem.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by qazplm114477
0

holy... never mind. I just solved it.

the problem was with how I instantiated the class. if it's in a namespace then a (\) is in order.

$a = new ArrayIterator;

//works just fine

namespace test;

$a = new ArrayIterator;

//get error
//Fatal error: Class 'test\ArrayIterator' not found in /www/ on line 3

//the fix
namespace test;

$a = new \ArrayIterator;

hopefully if someone has the same problem as me, this might help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.