-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
From PHP document ( https://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.nested ), it said Nested namespaces are not allowed.
Here is same of PHP namespaces in 2 styles.
01 Simple style
namespace MyProject;
const TASK_DATE = '';
namespace Another;
echo TASK_DATE;The echo line said Fatal error: Uncaught Error: Undefined constant "Another\TASK_DATE".
02 Bracket style
namespace MyProject {
const TASK_DATE = '';
}
namespace Another {
echo TASK_DATE;
}The result is same error Fatal error: Uncaught Error: Undefined constant "Another\TASK_DATE".
=> This mean that simple style Another namespace is not nested under MyProject same as bracket style did.
BUT.. the php-parser parse these two differently!
Simple style result
{
"kind": "program",
"children": [
{
"children": [
{
"name": "Another",
"withBrackets": false
}
],
"name": "MyProject",
"withBrackets": false
}
]
}Bracket style result
{
"kind": "program",
"children": [
{
"name": "Another",
"withBrackets": true
},
{
"name": "MyProject",
"withBrackets": true
}
]
}Since it is not allowed to nested namespace (from PHP document above) and the simple and bracket styles work the same, I think php parser should treat them the same as well. ??
JS Code I use to parse the PHP file.
// initialize a new parser instance
const parser = new engine({
// some options :
parser: {
extractDoc: true,
locations: true,
php8: true,
},
ast: {
withPositions: true,
},
lexer: {
all_tokens: true,
},
});
const phpFile = fs.readFileSync("./example.php");
// Log out results
console.log("File parse:", JSON.stringify(parser.parseCode(phpFile), null, 2));Metadata
Metadata
Assignees
Labels
No labels