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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.