php / php/doc-en

::class docs says it resolves to fully qualified namespace but actually only qualified namespace

Open
#2,138 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

From manual page: https://php.net/language.oop5.constants it says...

The special ::class constant allows for fully qualified class name resolution at compile time, this is useful for namespaced classes:

With https://www.php.net/manual/en/language.namespaces.rules.php saying that a fully qualified namespace is...

an identifier with a namespace separator that begins with a namespace separator, such as \Foo\Bar. The namespace \Foo is also a fully qualified name

However using ::class on a namespaced class doesn't include the initial namespace separator in its output.

[root@TPS-NUCI5-DEMO1 ~]# php -a
Interactive shell

php > require_once("vendor/autoload.php");
php > var_dump(\Twig\Loader\FilesystemLoader::class);
php shell code:1:
string(28) "Twig\Loader\FilesystemLoader"

Either ::class is behaving wrong or the documentation shouldn't say it resolves to a fully qualified class name.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the class constants page at language.oop5.constants and compare its wording with the namespace naming rules page at language.namespaces.rules.php. Confirm the documented ::class output for namespaced classes, then clarify the terminology so the statement matches the behavior and the namespace definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.