summaryrefslogtreecommitdiff
path: root/ext/reflection/tests/ReflectionProperty_hasDefaultValue.phpt
blob: 57090003707331969366dea57b15ec4a08d21b59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
--TEST--
reflection: ReflectionProperty::hasDefaultValue
--FILE--
<?php

class TestClass
{
    public $foo;
    public $bar = 'baz';

    public static $static1;
    public static $static2 = 1234;

    public int $val1;
    public int $val2 = 1234;

    public ?int $nullable;
    public ?int $nullable2 = null;
}

$property = new ReflectionProperty(TestClass::class, 'foo');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'bar');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'static1');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'static2');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'val1');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'val2');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'nullable');
var_dump($property->hasDefaultValue());

$property = new ReflectionProperty(TestClass::class, 'nullable2');
var_dump($property->hasDefaultValue());

$test = new TestClass;
$test->dynamic = null;
$property = new ReflectionProperty($test, 'dynamic');
var_dump($property->hasDefaultValue());

?>
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)