# Enumerate visible class names in current scope

- Thread: https://externals.io/message/74346
- Original archive: https://news-web.php.net/php.internals/74346
- Started by Aaron Lewis on 2014-05-19T08:28:02+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #74346 — Aaron Lewis — 2014-05-19T08:28:02+00:00

URL: https://externals.io/message/74346#74346

Hi,

Is it possible to enumerate all visible class name in current scope?

If not names, a zval like structure is nice as well.

Thanks!

-- 
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33

---

## #74347 — Kris Craig — 2014-05-19T08:44:02+00:00

URL: https://externals.io/message/74346#74347 · In reply to: #74346

On Mon, May 19, 2014 at 1:28 AM, Aaron Lewis <the.warl0ck.1989@gmail.com>wrote:

> Hi,
>
> Is it possible to enumerate all visible class name in current scope?
>
> If not names, a zval like structure is nice as well.
>
> Thanks!
>
> --
> Best Regards,
> Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
> Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33
>
> --
> 
> 
>
>
I know you can use `get_declared_classes()` to iterate through ALL declared
classes, but I don't know how it behaves with regard to scope and
visibility.  I do know that it includes both user-defined and predefined
classes in its output.

--Kris

---

## #74348 — Aaron Lewis — 2014-05-19T09:04:47+00:00

URL: https://externals.io/message/74346#74348 · In reply to: #74347

Hi Kris,

Thanks for the quick reply. I found class_table HashTable structure in
that zend function.

But, do you know how to tell between user-defined classes and predefined ones?




>
>
>
> On Mon, May 19, 2014 at 1:28 AM, Aaron Lewis <the.warl0ck.1989@gmail.com>
> wrote:
> > […]
>
> I know you can use `get_declared_classes()` to iterate through ALL declared
> classes, but I don't know how it behaves with regard to scope and
> visibility.  I do know that it includes both user-defined and predefined
> classes in its output.
>
> --Kris
>



-- 
Best Regards,
Aaron Lewis - PGP: 0x13714D33 - http://pgp.mit.edu/
Finger Print:   9F67 391B B770 8FF6 99DC  D92D 87F6 2602 1371 4D33

---

## #74359 — johannes@schlueters.de — 2014-05-19T12:37:54+00:00

URL: https://externals.io/message/74346#74359 · In reply to: #74348

> Hi Kris,
> 
> Thanks for the quick reply. I found class_table HashTable structure in
> that zend function.
> 
> But, do you know how to tell between user-defined classes and predefined ones?

Please take a minute or two to try to find answers to such questions
yourself. i.e. look at the class entry data structure, wonder whether
the "type" element might be related, grep for it and see that it is set
to either ZEND_INTERNAL_CLASS or ZEND_USER_CLASS. An alternative
approach to figure this out is to think about a way to get this
information from userspace, this should lead you to reflection, and that
to the implementation of ReflectionClass::isUserDefined() in
http://lxr.php.net/xref/PHP_TRUNK/ext/reflection/php_reflection.c#3574

Yes, the documentation is limited on these things but most things can be
figured out with some research. If you researched and are unsure feel
free to ask, and we are welcoming questions, but please mind that you
are sending the questions to a few hundred persons trying to follow the
PHP development ...

Thanks
johannes
