0

Basically I just want to require "some.class.php"; and know what class is inside that file.

The answer is:

Get the last value of the function get_declared_classes

ln -s
  • 325
  • 3
  • 12
  • I'm sorry this is not about namespaces ... so you shouldn't really mark it as duplicate it has nothing to do with namespaces. – ln -s Sep 10 '14 at 12:44
  • 1
    Agreed, have requested a reopen. However you do need to explain your question better. php5 does have reflection http://php.net/manual/en/book.reflection.php – Steve Sep 10 '14 at 12:46
  • 1
    I've also cast a reopen vote, but you should really remove the "yelling" from your most recent edit, and just clarify the question a little further. – jprofitt Sep 10 '14 at 12:48
  • I know I just hate automatons, reminds me of IRC OPs – ln -s Sep 10 '14 at 12:50
  • Your initial question was very hard to understand; jumping to the conclusion that it is something about namespaces was not completely unwarranted. Alternatively I'd have closed it as *Unclear*. No reason to misbehave, just clarify what exactly you're asking instead. – deceze Sep 10 '14 at 12:55
  • BTW, if you have an answer, go ahead and post it as answer; not within the question. Thanks! – deceze Sep 10 '14 at 12:57

1 Answers1

1
   require "Some.class.php";

   $loadedClasses = get_declared_classes();
   $lastClass     = array_pop($loadedClasses);

   echo "Last loaded class is $lastClass";
ln -s
  • 325
  • 3
  • 12
  • Note that there's absolutely no guarantee as far as I'm aware that `get_declared_classes` will always return classes in the order they were loaded. It is also possible that the file you `require` loads more classes itself. – deceze Sep 10 '14 at 14:03
  • Well I just want to know the LAST class so if it requires files inside it's fine by me. – ln -s Sep 10 '14 at 14:36