- 将 CompilerBase.php 中的 parseAssignOpBitwiseOr 方法从 private 改为 protected - 将 CompilerBase.php 中的 error 方法从 protected 改为 public - 在 gen_stub.php 中添加对属性数组参数的错误检查和提示 - 修复 Translator.php 中构建目录文件名使用 targetName 而非 getModuleName()pull/1/head
parent
588cd85ca4
commit
aa51b09fa9
6 changed files with 141 additions and 3 deletions
@ -0,0 +1,72 @@ |
|||||||
|
--TEST-- |
||||||
|
Attribute: 001 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
#[Attribute] |
||||||
|
class MyAttribute |
||||||
|
{ |
||||||
|
const VALUE = 'value'; |
||||||
|
|
||||||
|
private $value; |
||||||
|
|
||||||
|
public function __construct($value = null) |
||||||
|
{ |
||||||
|
$this->value = $value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#[MyAttribute] |
||||||
|
#[MyAttribute(1234)] |
||||||
|
#[MyAttribute(value: 1234)] |
||||||
|
#[MyAttribute(MyAttribute::VALUE)] |
||||||
|
#[MyAttribute([])] |
||||||
|
#[MyAttribute(100 + 200)] |
||||||
|
class Thing |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
#[MyAttribute(1234), MyAttribute(5678)] |
||||||
|
class AnotherThing |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$reflection = (new ReflectionClass(Thing::class)); |
||||||
|
$attributes = $reflection->getAttributes(); |
||||||
|
|
||||||
|
foreach ($attributes as $attribute) { |
||||||
|
var_dump($attribute->getName()); |
||||||
|
var_dump($attribute->getArguments()); |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(0) { |
||||||
|
} |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
int(1234) |
||||||
|
} |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(1) { |
||||||
|
["value"]=> |
||||||
|
int(1234) |
||||||
|
} |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
string(5) "value" |
||||||
|
} |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
array(0) { |
||||||
|
} |
||||||
|
} |
||||||
|
string(11) "MyAttribute" |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
int(300) |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
--TEST-- |
||||||
|
Attribute: 002 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[MyAttribute] |
||||||
|
class Thing |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$o = new Thing; |
||||||
|
var_dump($o); |
||||||
|
|
||||||
|
$reflection = new ReflectionClass(Thing::class); |
||||||
|
$attributes = $reflection->getAttributes(MyAttribute::class); |
||||||
|
var_dump($attributes); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
object(Thing)#1 (0) { |
||||||
|
} |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
object(ReflectionAttribute)#3 (1) { |
||||||
|
["name"]=> |
||||||
|
string(11) "MyAttribute" |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
--TEST-- |
||||||
|
Attribute: 003 |
||||||
|
--SKIPIF-- |
||||||
|
<?php die("skip"); ?> |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[MyAttribute([1, 2, 3])] |
||||||
|
class Thing |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
function main() { |
||||||
|
$o = new Thing; |
||||||
|
var_dump($o); |
||||||
|
|
||||||
|
$reflection = new ReflectionClass(Thing::class); |
||||||
|
$attributes = $reflection->getAttributes(MyAttribute::class); |
||||||
|
foreach ($attributes as $attribute) { |
||||||
|
var_dump($attribute->getName()); |
||||||
|
var_dump($attribute->getArguments()); |
||||||
|
} |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
object(Thing)#1 (0) { |
||||||
|
} |
||||||
|
array(1) { |
||||||
|
[0]=> |
||||||
|
object(ReflectionAttribute)#3 (1) { |
||||||
|
["name"]=> |
||||||
|
string(11) "MyAttribute" |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue