parent
e2c32adda2
commit
f03c0b12c6
8 changed files with 212 additions and 30 deletions
@ -0,0 +1,28 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
interface DnfLeft |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
interface DnfRight |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
enum DnfBoth implements DnfLeft, DnfRight |
||||||
|
{ |
||||||
|
case Value; |
||||||
|
} |
||||||
|
|
||||||
|
class DnfConstantParent |
||||||
|
{ |
||||||
|
const (DnfLeft&DnfRight)|stdClass VALUE = DnfBoth::Value; |
||||||
|
} |
||||||
|
|
||||||
|
class DnfConstantChild extends DnfConstantParent |
||||||
|
{ |
||||||
|
const DnfLeft&DnfRight VALUE = DnfBoth::Value; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
interface ConstantCycleA extends ConstantCycleB |
||||||
|
{ |
||||||
|
const int A = 1; |
||||||
|
} |
||||||
|
|
||||||
|
interface ConstantCycleB extends ConstantCycleA |
||||||
|
{ |
||||||
|
const int B = 2; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,20 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
interface TraitConstantContract |
||||||
|
{ |
||||||
|
const int VALUE = 1; |
||||||
|
} |
||||||
|
|
||||||
|
trait IncompatibleConstantTrait |
||||||
|
{ |
||||||
|
const string VALUE = 'wrong'; |
||||||
|
} |
||||||
|
|
||||||
|
class TraitConstantImplementation implements TraitConstantContract |
||||||
|
{ |
||||||
|
use IncompatibleConstantTrait; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
--TEST-- |
||||||
|
Typed class and interface constants support covariant overrides at runtime |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
interface TypedConstantContract |
||||||
|
{ |
||||||
|
const int|string NUMBER = 1; |
||||||
|
const ?int OPTIONAL = null; |
||||||
|
} |
||||||
|
|
||||||
|
trait CompatibleConstantTrait |
||||||
|
{ |
||||||
|
const int TRAIT_VALUE = 3; |
||||||
|
} |
||||||
|
|
||||||
|
class TypedConstantBase |
||||||
|
{ |
||||||
|
const int|string VALUE = 1; |
||||||
|
const ?int EMPTY_VALUE = null; |
||||||
|
} |
||||||
|
|
||||||
|
class TypedConstantChild extends TypedConstantBase implements TypedConstantContract |
||||||
|
{ |
||||||
|
use CompatibleConstantTrait; |
||||||
|
|
||||||
|
const int VALUE = 2; |
||||||
|
const int EMPTY_VALUE = 6; |
||||||
|
const int NUMBER = 4; |
||||||
|
const int OPTIONAL = 5; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
var_dump(TypedConstantBase::VALUE); |
||||||
|
var_dump(TypedConstantBase::EMPTY_VALUE); |
||||||
|
var_dump(TypedConstantChild::VALUE); |
||||||
|
var_dump(TypedConstantChild::EMPTY_VALUE); |
||||||
|
var_dump(TypedConstantChild::NUMBER); |
||||||
|
var_dump(TypedConstantChild::OPTIONAL); |
||||||
|
var_dump(TypedConstantChild::TRAIT_VALUE); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(1) |
||||||
|
NULL |
||||||
|
int(2) |
||||||
|
int(6) |
||||||
|
int(4) |
||||||
|
int(5) |
||||||
|
int(3) |
||||||
Loading…
Reference in new issue