Question about class `implements` and `extends`
ninthDevilHAUNSTER opened this issue · 1 comments
ninthDevilHAUNSTER commented
Platform : Ubuntu 20.04
php version : 7.4
php-ast version : 80
I meet a problem about extends and implements attribute in parsing AST_CLASS objects.
Here is the example script
// t.php
<?php
interface b
{
public function bar();
}
interface c extends b
{
public function baz();
}
class d implements c
{
public function bar()
{
// TODO: Implement bar() method.
}
public function baz()
{
// TODO: Implement baz() method.
}
}
After I parse this script with following script
include 'util.php';
$path = "t.php";
$ast = ast\parse_file($path, $version = 80);
echo ast_dump($ast);
I found something wrong with implements attribute about class c
,
I think the child of implements attribute should be null and the extends attribute should be the value of implements attribute.
1: AST_CLASS
flags: CLASS_INTERFACE (1)
name: "c"
docComment: null
extends: null
implements: AST_NAME_LIST // this AST_NAME_LIST should exist in extends attribute ?
0: AST_NAME
flags: NAME_NOT_FQ (1)
name: "b"
stmts: AST_STMT_LIST
0: AST_METHOD
flags: MODIFIER_PUBLIC (1)
name: "baz"
docComment: null
params: AST_PARAM_LIST
stmts: null
returnType: null
attributes: null
__declId: 2
attributes: null
__declId: 3
2: AST_CLASS
flags: 0
name: "d"
docComment: null
extends: null
implements: AST_NAME_LIST
0: AST_NAME
flags: NAME_NOT_FQ (1)
name: "c"
stmts: AST_STMT_LIST
0: AST_METHOD
flags: MODIFIER_PUBLIC (1)
name: "bar"
docComment: null
params: AST_PARAM_LIST
stmts: AST_STMT_LIST
returnType: null
attributes: null
__declId: 4
1: AST_METHOD
flags: MODIFIER_PUBLIC (1)
name: "baz"
docComment: null
params: AST_PARAM_LIST
stmts: AST_STMT_LIST
returnType: null
attributes: null
__declId: 5
attributes: null
__declId: 6
nikic commented
extends
for interfaces is equivalent to implements
for classes, and PHP represents it internally as such to allow more uniform treatment. The ast extension uses the same internal representation.