Parsing is incorrect for extends of root-namespace classes

Created on 7 October 2019, almost 6 years ago
Updated 4 June 2025, 3 months ago

If you have code like this:

namespace Foo;

interface ConstraintViolationListInterface extends \Traversable, \Countable, \ArrayAccess

When we parse it out, and then convert the individual extend items to string with:

            foreach ($statement->extends as $extend) {
              $docblock['extends'][] = $extend->toString();
            }

I am getting "Traversable" "Countable", "ArrayAccess", without the leading \, from the PHP parser [This is in api.parser.inc in _api_build_php_docblocks()].

Then I pass any extends I find through api_full_classname(). And when it gets something without a leading \, it (correctly) assumes it should be in the namespace of the overall file. So, instead of \Traversable being recognized as a PHP built-in interface in the root namespace, it is instead thinking it is \Foo\Traversable.

Note that I found another interface in the codebase that is working correctly -- but it has use statements at the top of its file, such as

use Traversable;

which means that "Traversable" without the \ means \Traversable for that file. The api_full_classname() function always takes into account the use statements, so it's working correctly for that interface.

We're unfortunately currently using an old version of the PHP parser. So... I'll probably have to postpone fixing this until I can upgrade to a newer version and see if it's still a problem there, and then if so, take it up with the PHP parser project. See
πŸ“Œ Test/update API module for new Parser code version Closed: outdated

πŸ› Bug report
Status

Active

Version

2.0

Component

Parser

Created by

πŸ‡ΊπŸ‡ΈUnited States jhodgdon Spokane, WA, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024