# get_class inconsistency

- Thread: https://externals.io/message/51520
- Original archive: https://news-web.php.net/php.internals/51520
- Started by Martin Scotta on 2011-02-23T18:14:45+00:00
- Messages: 2
- 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

---

## #51520 — Martin Scotta — 2011-02-23T18:14:45+00:00

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

Hi all,

would it be safer that get_class return the fully qualified class name ?

namespace A\B\C {
    class Test { }
    echo get_class( new Test ); // it prints A\B\C\Test
};

It should print \A\B\C\Test, as explained
http://php.net/manual/en/language.namespaces.rules.php

 Martin Scotta

---

## #51521 — Benjamin Eberlei — 2011-02-23T18:48:18+00:00

URL: https://externals.io/message/51520#51521 · In reply to: #51520

No, this wouldnt be backwards compatible to the PHP 5.2 behavior, hence inconsistent.

The convention is class names in strings are ALWAYS fully qualified, therefore the prefix backslash is not necessary.

On Wed, 23 Feb 2011 15:14:45 -0300
Martin Scotta <martinscotta@gmail.com> wrote:

> Hi all,
> 
> would it be safer that get_class return the fully qualified class name ?
> 
> namespace A\B\C {
>     class Test { }
>     echo get_class( new Test ); // it prints A\B\C\Test
> };
> 
> It should print \A\B\C\Test, as explained
> http://php.net/manual/en/language.namespaces.rules.php
> 
>  Martin Scotta
