parent
8c3cbd4dce
commit
82739d3d66
9 changed files with 233 additions and 24 deletions
@ -0,0 +1,12 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class PropertyDefaultClassConstType |
||||||
|
{ |
||||||
|
public int $value = self::DEFAULT_VALUE; |
||||||
|
|
||||||
|
private const DEFAULT_VALUE = 'invalid'; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class PropertyDefaultExpressionType |
||||||
|
{ |
||||||
|
public int $value = 1.5 + 2; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class PropertyDefaultFalseForTrue |
||||||
|
{ |
||||||
|
public true $value = false; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
class PropertyDefaultTrueForFalse |
||||||
|
{ |
||||||
|
public false $value = true; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
} |
||||||
@ -0,0 +1,53 @@ |
|||||||
|
--TEST-- |
||||||
|
Property defaults support constant expressions, inheritance, and traits |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
const GLOBAL_NUMBER = 4; |
||||||
|
|
||||||
|
trait PropertyDefaultsTrait |
||||||
|
{ |
||||||
|
public int $traitValue = 10 + 1; |
||||||
|
public static string $traitStatic = 'trait' . '-static'; |
||||||
|
} |
||||||
|
|
||||||
|
class PropertyDefaultsParent |
||||||
|
{ |
||||||
|
private const LABEL_PREFIX = 'parent'; |
||||||
|
|
||||||
|
public int $sum = 1 + 2; |
||||||
|
public float $ratio = 2; |
||||||
|
protected string $label = self::LABEL_PREFIX . '-value'; |
||||||
|
public static int $counter = GLOBAL_NUMBER + 1; |
||||||
|
public static float $staticRatio = 3; |
||||||
|
|
||||||
|
public function label(): string |
||||||
|
{ |
||||||
|
return $this->label; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class PropertyDefaultsChild extends PropertyDefaultsParent |
||||||
|
{ |
||||||
|
use PropertyDefaultsTrait; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$value = new PropertyDefaultsChild(); |
||||||
|
var_dump($value->sum, $value->ratio, $value->label(), $value->traitValue); |
||||||
|
var_dump( |
||||||
|
PropertyDefaultsChild::$counter, |
||||||
|
PropertyDefaultsChild::$staticRatio, |
||||||
|
PropertyDefaultsChild::$traitStatic |
||||||
|
); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(3) |
||||||
|
float(2) |
||||||
|
string(12) "parent-value" |
||||||
|
int(11) |
||||||
|
int(5) |
||||||
|
float(3) |
||||||
|
string(12) "trait-static" |
||||||
Loading…
Reference in new issue