fix: 修复类常量使用self作为方法参数默认值 #16
Merged
韩天峰
merged 2 commits from fix-class-const-default-value into master 2 months ago
5 changed files with 176 additions and 4 deletions
@ -0,0 +1,15 @@ |
||||
<?php |
||||
|
||||
class LazyArrayObject extends \ArrayObject |
||||
{ |
||||
public function test($value1 = self::ARRAY_AS_PROPS, $value2 = LazyArrayObject::ARRAY_AS_PROPS, $value3 = \ArrayObject::ARRAY_AS_PROPS) |
||||
{ |
||||
var_dump($value1, $value2, $value3); |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$test = new LazyArrayObject; |
||||
$test->test(); |
||||
} |
||||
@ -0,0 +1,47 @@ |
||||
--TEST-- |
||||
Class constant as default parameter value (self / class name / FQCN, including constant inherited from an internal parent class) |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class LazyArrayObject extends \ArrayObject |
||||
{ |
||||
public const NULL_VALUE = null; |
||||
|
||||
public function test($value1 = self::ARRAY_AS_PROPS, $value2 = LazyArrayObject::ARRAY_AS_PROPS, $value3 = \ArrayObject::ARRAY_AS_PROPS) |
||||
{ |
||||
var_dump($value1, $value2, $value3); |
||||
} |
||||
|
||||
public function nullDefault($value = self::NULL_VALUE) |
||||
{ |
||||
var_dump($value); |
||||
} |
||||
} |
||||
|
||||
class ParentDefaultValue |
||||
{ |
||||
public const VALUE = 42; |
||||
} |
||||
|
||||
class ChildDefaultValue extends ParentDefaultValue |
||||
{ |
||||
public function inheritedDefault($value = self::VALUE) |
||||
{ |
||||
var_dump($value); |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$test = new LazyArrayObject; |
||||
$test->test(); |
||||
$test->nullDefault(); |
||||
(new ChildDefaultValue)->inheritedDefault(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(2) |
||||
int(2) |
||||
int(2) |
||||
NULL |
||||
int(42) |
||||
Loading…
Reference in new issue