parent
559a8860a0
commit
46ff43ba62
4 changed files with 149 additions and 12 deletions
@ -0,0 +1,52 @@ |
||||
--TEST-- |
||||
property default value is array with mixed declared type |
||||
--FILE-- |
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
class Test |
||||
{ |
||||
private mixed $value = []; |
||||
|
||||
public function __construct(mixed $value) |
||||
{ |
||||
$this->value = $value; |
||||
} |
||||
|
||||
public function getValue(): mixed |
||||
{ |
||||
return $this->value; |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$test = new Test(123); |
||||
var_dump($test->getValue()); |
||||
|
||||
$test = new Test('test'); |
||||
var_dump($test->getValue()); |
||||
|
||||
$test = new Test([1, 2, 3]); |
||||
var_dump($test->getValue()); |
||||
|
||||
$test = new Test(new stdClass); |
||||
$v = $test->getValue(); |
||||
var_dump($v instanceof stdClass); |
||||
var_dump(get_class($v)); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
int(123) |
||||
string(4) "test" |
||||
array(3) { |
||||
[0]=> |
||||
int(1) |
||||
[1]=> |
||||
int(2) |
||||
[2]=> |
||||
int(3) |
||||
} |
||||
bool(true) |
||||
string(8) "stdClass" |
||||
@ -0,0 +1,55 @@ |
||||
--TEST-- |
||||
various property default values (array, int, float, string, bool, null, const) |
||||
--FILE-- |
||||
<?php |
||||
|
||||
class Test |
||||
{ |
||||
public $untypedArray = []; |
||||
public mixed $mixedArray = []; |
||||
public array $typedArray = []; |
||||
public $untypedInt = 123; |
||||
public int $typedInt = 123; |
||||
public float $typedFloat = 1.5; |
||||
public string $typedString = 'hello'; |
||||
public bool $typedBool = true; |
||||
public $untypedNull = null; |
||||
public $untypedConst = PHP_INT_MAX; |
||||
|
||||
public function show(): void |
||||
{ |
||||
var_dump( |
||||
$this->untypedArray, |
||||
$this->mixedArray, |
||||
$this->typedArray, |
||||
$this->untypedInt, |
||||
$this->typedInt, |
||||
$this->typedFloat, |
||||
$this->typedString, |
||||
$this->typedBool, |
||||
$this->untypedNull, |
||||
$this->untypedConst |
||||
); |
||||
} |
||||
} |
||||
|
||||
function main() |
||||
{ |
||||
$t = new Test(); |
||||
$t->show(); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
array(0) { |
||||
} |
||||
array(0) { |
||||
} |
||||
array(0) { |
||||
} |
||||
int(123) |
||||
int(123) |
||||
float(1.5) |
||||
string(5) "hello" |
||||
bool(true) |
||||
NULL |
||||
int(9223372036854775807) |
||||
Loading…
Reference in new issue