title: In PHP, is there a way to get all declared classes in a specific namespace?
body: <p>I'd like to get the names of all classes within a specific namespace in PHP. Currently, I'm attempting to do some magic via reflection on a specific list of named classes, but I'd like to do it without knowing the names ahead of time.</p>
  
  <p>I've tried calling <code>get_declared_classes()</code>, but for whatever reason, classes that I do have available are not showing up. I can call <code>get_declared_classes()</code>, not see <code>Event</code> in the list, then immediately call <code>$x = new Event()</code> without a problem. Something like the following, which I would think should cause a problem...</p>
  
  <pre><code>if (! in_array('Event', get_declared_classes())) { $x = new Event(); }
  </code></pre>
  
  <p>...works fine. I'm wondering if namespacing these classes and retrieving that way would help alleviate the problem. Is this possible?</p>
  
  <p>EDIT: For clarification, let me add that I am not currently using namespaces, and I am not specifically trying to achieve something from the above listed code. What I want is to get the names of all classes I have declared. Despite the fact the class declarations for all of them are being hit before I call <code>get_declared_classes()</code>, they are not all appearing in the list. I was hoping that namespacing might help solve the problem.</p>
  
  <p>EDIT2: Several people have pointed out that the classes may be autoloaded. I tested this by doing the following. <code>echo(class_exists('Event'))</code> returned a value of <code>1</code>. <code>echo(class_exists('Event', FALSE))</code> returned a value of 0. The second, optional parameter to class_exists is whether or not to autoload. So, apparently the class is being autoloaded. That answers that.</p>
  
  <p>So, next question - how do I prevent this? I'm using a framework that really doesn't give me much low-level control. Is there a way to force autoloading, THEN call <code>get_declared_classes</code>, or for <code>get_declared_classes</code> to fire an autoload first?</p>