Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typed Properties #3313

Closed
wants to merge 420 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
420 commits
Select commit Hold shift + click to select a range
03861bd
Reverted incomplete fix
dstogov May 25, 2016
be071cd
Fixed test
dstogov May 25, 2016
c992fcf
A better to fix for source zval separation on type conversion caused …
dstogov May 25, 2016
f4b4051
Changed behavior of uninitialized nullable properties (accoding to co…
dstogov May 25, 2016
e657bf8
Revert useless changes
dstogov May 25, 2016
d46695d
Removed useless check (references are never fetched using FETCH_OBJ_RW)
dstogov May 25, 2016
a53b8ac
Removed duplicate code
dstogov May 25, 2016
d248c27
Added support for nullavle types in AST pretty printer
dstogov May 25, 2016
e1017f9
Revert useless change
dstogov May 25, 2016
291d431
Added test (memory leaks)
dstogov May 25, 2016
40aa6c2
"string" mat be also a valid "callable"
dstogov May 25, 2016
3143597
Removed unused function and macro
dstogov May 25, 2016
4506a70
Optimization
dstogov May 25, 2016
05dd2e4
Removed unused zend_object_fetch_property_type_info() and renamed zen…
dstogov May 25, 2016
023df77
Fixed wrong exception when passing element of typed property by refer…
dstogov May 25, 2016
56e2aaa
Optimisation
dstogov May 25, 2016
d7f313e
Added test (failed with valgrind)
dstogov May 25, 2016
892994d
Added test (failed with valgrind)
dstogov May 25, 2016
b0dcf0c
Fixed memory leak
dstogov May 25, 2016
2019f66
Check type after constant resolution
dstogov May 25, 2016
c304c6b
Support for type checks of named constants in property default values.
dstogov May 25, 2016
b2cebf6
Fixed memory leaks
dstogov May 26, 2016
8bc2078
Faster +=/++/--
dstogov May 26, 2016
26bf822
Merge branch 'master' into typed-properties
dstogov May 26, 2016
865686f
Fixed ZTS compatibility
dstogov May 26, 2016
bf875fb
Fixed compilation warning
dstogov May 26, 2016
fc41cdc
fixed white-spaces
dstogov May 26, 2016
8beea3d
Optimization
dstogov May 26, 2016
13c86d9
Cleanup ext/reflection changes
dstogov May 26, 2016
697b1b1
Moved BG(unserialize_refs) into php_unserialize_data_t
dstogov May 26, 2016
c5e45ff
Keep GCC from incorrect over-optimisation
dstogov May 26, 2016
6bb1fa9
Removed useles code (default value should be already properly set in …
dstogov May 27, 2016
5811e86
Don't mess NULL and UNDEF default value back and force. Set proper va…
dstogov May 27, 2016
037da58
Remove duplicate checks
dstogov May 27, 2016
03e7112
Fixed incorrect argument types
dstogov May 27, 2016
cc19dc5
Remove bad checks for simple property inheritance
bwoebi May 28, 2016
3bbe52d
Merge branch 'master' of https://github.com/php/php-src into typed-pr…
krakjoe Jun 7, 2016
de84f50
changes prompted by review
krakjoe Jun 7, 2016
71cda1b
make consistent with RFC (nullables)
krakjoe Jun 7, 2016
8eec27f
fix inheritance error
krakjoe Jun 7, 2016
67ffff9
Merge branch 'master' into typed_properties
bwoebi Nov 6, 2016
1b8bd88
Initial ref types patch
bwoebi Nov 10, 2016
0efa68b
Fix make test
bwoebi Nov 13, 2016
a75e03a
Take properly care of cases where the by-ref value is *consumed* first
bwoebi Nov 13, 2016
433e637
Remove all the nice code making it actually worse again ...
bwoebi Nov 13, 2016
f4ea705
Use reftype, not its location...
bwoebi Nov 13, 2016
ad85b55
few changes for bob to check
krakjoe Nov 13, 2016
c347d8d
Merge branch 'typed_ref_properties' of https://github.com/bwoebi/php-…
krakjoe Nov 13, 2016
2769866
more zpp changes
krakjoe Nov 13, 2016
8d3a9f6
finish pcntl, probably
krakjoe Nov 13, 2016
d7c7b9c
some of sockets
krakjoe Nov 13, 2016
cd32f63
more zpppppp stuff
krakjoe Nov 13, 2016
a0aaeed
use macros that actually exist, rather than nonsense
krakjoe Nov 13, 2016
93707d7
Fix a ton of bugs and tests
bwoebi Nov 14, 2016
bb230fd
Add more guards for typed by-ref assign + fixes
bwoebi Nov 18, 2016
38583b9
Fix a few more tests
bwoebi Nov 18, 2016
fea2aa8
typo; s/zend_get_long/zval_get_long/
bwoebi Nov 18, 2016
d9b964e
Fix iterator_035.phpt and pcntl/003.phpt
bwoebi Nov 19, 2016
0cc95b8
Remove lchown($file, -5); test
bwoebi Nov 19, 2016
694752b
Merge branch 'master' into typed_ref_properties
bwoebi Nov 19, 2016
d5b3bd8
Add support for by-ref foreach
bwoebi Nov 19, 2016
0bf02dc
Separate static property assignment out into dedicated assign ops
bwoebi Dec 1, 2016
4c57735
Merge remote-tracking branch 'origin' into typed_ref_properties
bwoebi Dec 7, 2016
786d4bb
Fixed optimizer support for ZEND_ASSIGN_OBJ_REF
dstogov Dec 9, 2016
a9b0cd7
Implemented type inference support for typed properties.
dstogov Dec 9, 2016
41d3882
Merge branch 'master' into typed_ref_properties
bwoebi Jan 9, 2017
3e9d02e
Merge remote-tracking branch 'github/typed_ref_properties' into typed…
bwoebi Jan 9, 2017
f56bd39
Fixed tests (made them 32/64-bit independent)
dstogov Jan 10, 2017
354c1af
Fix a bunch of bugs related to e8109e09
bwoebi Jan 11, 2017
69c7210
Merge branch 'master' into typed_ref_properties
dstogov Jan 13, 2017
f2872c9
Merge branch 'master' of https://github.com/php/php-src into typed_re…
bwoebi Jan 15, 2017
e20a1a3
Fix crash in pcntl_wait()
bwoebi Jan 15, 2017
b021ec8
Merge branch 'master' into typed_ref_properties
dstogov Jan 16, 2017
629521e
Fix constant value overwrite
bwoebi Jan 16, 2017
78dae20
Add support for iterable typed properties
bwoebi Jan 16, 2017
bafcfc0
Merge branch 'master' into typed_ref_properties
nikic Jun 6, 2018
965f2c8
Fix build failures
nikic Jun 6, 2018
f42495d
Initial ref type in MAKE_REF_EX
nikic Jun 6, 2018
ed00f11
Solve the clashing FETCH_REF|CACHE_SLOT
bwoebi Jun 7, 2018
6709fbb
Fix few tests
bwoebi Jun 7, 2018
f55663f
Fix cache_slot of ASSIGN_OBJ_REF
bwoebi Jun 8, 2018
6d0c443
Opcache fixes
bwoebi Jun 8, 2018
c453c98
Fix build failure in exif
bwoebi Jun 8, 2018
64a309f
Add one more test for iterables by ref
bwoebi Jun 8, 2018
98019a9
Fix foreach object iteration with holes
bwoebi Jun 8, 2018
e74f89c
Merge branch 'master' into typed_ref_properties
nikic Jun 9, 2018
83ec0df
Restore old code for post_incdec as well
nikic Jun 9, 2018
7f59681
Adjust test with new behavior
nikic Jun 9, 2018
1b0bc33
Fix compiler warning
nikic Jun 9, 2018
fcba7fe
Merge branch 'master' into typed_ref_properties
nikic Jun 9, 2018
2e28eb6
Improve default value handling
nikic Jun 9, 2018
4473554
Allow int default value for float properties
nikic Jun 9, 2018
4ef0626
Use not_in_object_context helper
nikic Jun 9, 2018
14081d8
Merge branch 'master' into typed_ref_properties
nikic Jun 9, 2018
cb75a25
Fix ASSIGN_OBJ_REF implementation
nikic Jun 9, 2018
3021bbc
Don't automatically initialize nullable prop to null
nikic Jun 11, 2018
230142e
Forbid callable type hint in typed properties
nikic Jun 12, 2018
b3da284
Merge branch 'extra_static_prop_assign_ops' into typed_ref_properties
bwoebi Jun 13, 2018
b707745
Merge branch 'typed_ref_properties' of https://github.com/bwoebi/php-…
bwoebi Jun 13, 2018
759d078
Add support for typed static properties (no opcache yet)
bwoebi Jun 14, 2018
ea58600
Fix assign to typed ref with weak type conversion
bwoebi Jun 14, 2018
149fd4b
Fix opcache for typed static properties
bwoebi Jun 14, 2018
bb0e169
Fix remaining tests
bwoebi Jun 14, 2018
ddfa19d
Fixing conversion with __get() on uninit typed properties
bwoebi Jun 15, 2018
8e23778
Prevent constant propagation into ASSIGN_*_REF OP_DATA
bwoebi Jun 15, 2018
fffb439
Add ZEND_PRE/POST_INC/DEC_STATIC_PROP
bwoebi Jun 15, 2018
17bdcef
Property compute intersection types for $obj->prop =& $ref
nikic Jun 15, 2018
40079bf
Add missing test file...
nikic Jun 15, 2018
bc900ea
Fix leak
nikic Jun 15, 2018
a450c28
$a->b = $c must return (string) $c if $a->b is of type string
bwoebi Jun 16, 2018
ebb64ae
Drop overeager assert
nikic Jun 16, 2018
7c96afa
Enforce reference checks on ReflectionClass::setStaticPropertyValue()…
bwoebi Jun 17, 2018
10ac526
Use coercive mode for setStaticPropertyValue()
bwoebi Jun 17, 2018
452d0a7
Keep track of reference types
bwoebi Jun 18, 2018
0023518
Fix memory leaks & stupid bugs introduced in last commit
bwoebi Jun 19, 2018
c69f8d0
Fix static property ref assignment without types
bwoebi Jun 19, 2018
f00a4df
extract() must check typed refs when overwriting
bwoebi Jun 20, 2018
1228d70
Mark subpats as ARRAY_ASSIGNABLE
nikic Jun 20, 2018
440a78a
Use TRY_ASSIGN_LONG for zcount parameters
nikic Jun 20, 2018
c6f5f13
Fix refcounting of zend_try_assign()
bwoebi Jun 20, 2018
df4460e
Merge branch 'master' into typed_ref_properties
nikic Jun 21, 2018
693a603
Enforce reference type in settype()
nikic Jun 21, 2018
2d47e84
Make ZEND_TRY_ASSIGN_* implementation less magic
nikic Jun 21, 2018
f6ad85f
Unmangle property name before printing
nikic Jun 21, 2018
898cd3d
Fix reference type tracking on clone
bwoebi Jun 22, 2018
5ce6ebc
Merge branch 'master' of https://github.com/php/php-src into typed_re…
bwoebi Jun 25, 2018
767b2e5
Update extensions for ZEND_TRY_ASSIGN_*
nikic Jun 25, 2018
13eba68
Merge branch 'master' into typed_ref_properties
nikic Jun 25, 2018
a3f60c0
Opcache handling fixes and improvements
nikic Jun 26, 2018
a19b2cc
Merge remote-tracking branch 'php-src/master' into typed_ref_properties
nikic Jun 27, 2018
062de9d
Reduce ASSIGN_STATIC_PROP_REF specialization
nikic Jun 27, 2018
c91ea15
Accept BP type in get_static_property
nikic Jun 27, 2018
50b1cf3
Prevent type violations via array auto-promotion
bwoebi Jun 28, 2018
4ce995d
Fix type check for array promotion check
bwoebi Jun 28, 2018
dc88db9
Merge branch 'master' into typed_ref_properties
nikic Jun 28, 2018
406d594
Restore fast-path check for uninitialized static property
nikic Jun 28, 2018
561f868
Add ReflectionProperty::isInitialized()
bwoebi Jun 30, 2018
157a09d
Merge branch 'master' into typed_ref_properties
nikic Jun 30, 2018
04aaea8
Minor cleanups
nikic Jun 30, 2018
e8dc511
Fix refcount on std_write_property with coercion
bwoebi Jul 1, 2018
ef67def
Fix ReflectionProperty::isInitialized() for dynamic props
nikic Jul 2, 2018
050f642
Fix ReflectionProperty::setValue() on typed static property
nikic Jul 2, 2018
7d3768b
Merge branch 'master' into typed_ref_properties
nikic Jul 2, 2018
8355232
Fix class check
nikic Jul 2, 2018
13777bd
References are the intersection of all present property types at any …
bwoebi Jul 2, 2018
428a00f
Fix a last test
bwoebi Jul 2, 2018
e888cf1
Remove 't' zpp type
nikic Jul 3, 2018
d35b338
Drop ARRAY_ASSIGNABLE as well
nikic Jul 3, 2018
dee7710
Merge branch 'master' into typed_ref_properties
nikic Jul 4, 2018
3bfbbf8
Abort early on exception in extract()
nikic Jul 4, 2018
acd013c
Move throwing of error into verify_ref_assignable_zval()
nikic Jul 4, 2018
a10222e
Don't constrain type intersections
nikic Jul 3, 2018
2eadd9e
Merge branch 'master' of https://github.com/php/php-src into typed_re…
bwoebi Jul 11, 2018
ae8a198
Fix build without execute_data $register
bwoebi Jul 11, 2018
eda393b
Move push/pop function prologue off fast path in VM
bwoebi Jul 13, 2018
1f73729
Resolve aliases during property type LSP checks
nikic Jul 16, 2018
7f25e95
Check for conflicting property types in traits
nikic Jul 16, 2018
398027b
Fix write_property handlers and add zend_std_get_property_with_info
bwoebi Jul 21, 2018
e7b86fb
Remove *tmp arg from zend_verify_property_type()
bwoebi Jul 21, 2018
92302a8
Remove useless separations/copies
bwoebi Jul 21, 2018
ffbf025
handle by ref mysqli/PDO statement result binding
bwoebi Jul 31, 2018
5e2ebdc
Fix string length updates
bwoebi Aug 15, 2018
5c94955
Merge branch 'master' into typed_ref_properties
bwoebi Aug 15, 2018
ae3e788
Fix a last function to use zend_try_assign()
bwoebi Aug 15, 2018
872084b
Fix non-string key usage with typed properties
bwoebi Aug 15, 2018
c6310fb
Merge remote-tracking branch 'origin/master' into typed_ref_properties
bwoebi Sep 12, 2018
a7fc684
Merge remote-tracking branch 'origin/master' into typed_ref_properties
bwoebi Sep 13, 2018
4f2350e
Merge remote-tracking branch 'php-src/master' into typed_ref_properties
nikic Sep 22, 2018
0d579d0
Add test for typed properties with integer keys
bwoebi Sep 22, 2018
5ba37d8
Remove unnecessary EXPECTFs
nikic Sep 22, 2018
aa9a8dd
One more EXPECTF case
nikic Sep 22, 2018
8e0380b
Use seen_prop when reporting weak type error
nikic Sep 22, 2018
f1a2522
Add test for settype() on typed reference
nikic Sep 22, 2018
1f235d3
Merge branch 'master' into typed_ref_properties
nikic Sep 22, 2018
8df6714
Minor test improvements
nikic Sep 23, 2018
96ea906
Drop redundant "Typed" prefix from callable/void error
nikic Sep 23, 2018
494585f
Restore old zend_binary_assign_op_obj_dim code
nikic Sep 23, 2018
e8cf005
Revert some unnecessary changes
nikic Sep 23, 2018
c44eba9
Change zend_declare_typed_property to accept zend_type
bwoebi Sep 24, 2018
7424833
Fix parent private property type affecting child class
bwoebi Sep 24, 2018
aa769fb
Remove redundant ISUNDEF checks in mysqlnd
bwoebi Sep 24, 2018
eff6b11
Handle NULL result in assign_ref
nikic Sep 24, 2018
1147467
Fix DateInterval write_property handler
nikic Sep 24, 2018
236a72f
Cleanup tests and improve a few error messages
bwoebi Sep 24, 2018
f697a7b
Fix two more tests in ext/standard
bwoebi Sep 24, 2018
f2d72b9
Evaluate expressions involving constants in property initializers acc…
bwoebi Sep 25, 2018
c78d5f6
Make visibility a property of the prop_group AST node
bwoebi Sep 25, 2018
ce68539
Enforce strict types for property initializer evaluation
bwoebi Sep 25, 2018
68abea6
Remove REF flag from ASSIGN_(OBJ|STATIC_PROP)_REF
nikic Sep 27, 2018
e1508f2
Add a missing ASSIGN_STATIC_PROP_REF case
nikic Sep 27, 2018
64c7ca8
Merge branch 'master' into typed_ref_properties
nikic Sep 27, 2018
fe4f9f3
Don't return pointer to stack memory
nikic Sep 27, 2018
ccf4481
Initialize return value for one exception case
nikic Sep 27, 2018
7a91259
Merge branch 'master' into typed_ref_properties
nikic Sep 28, 2018
313590d
Correctly handle resolved types in reflection
nikic Sep 28, 2018
98b8e8e
Remove unused enum
nikic Sep 28, 2018
6f9eac9
Only lookup prop info for INDIRECT
nikic Sep 28, 2018
b8881f0
Fix usage of self typehint in static trait properties
bwoebi Sep 29, 2018
de9a77f
Fix typed unint static property taken by ref being undefined
bwoebi Sep 29, 2018
f7e6099
Merge branch 'master' into typed_ref_properties
nikic Sep 29, 2018
4ca4996
Fix reflection after recent master changes
nikic Sep 29, 2018
3e7ecb3
Merge remote-tracking branch 'php-src/master' into typed_ref_properties
nikic Sep 30, 2018
23b1d0a
Simplify code using compile_typename
nikic Sep 30, 2018
f1e09b3
Fix tests for master changes
nikic Sep 30, 2018
02f3baa
Fix cache slot invalidation
nikic Sep 30, 2018
c38032a
Prevent any incdec on integer boundaries with typed properties
bwoebi Sep 30, 2018
1d555b7
Fix leak when modifying typed property during assignment
bwoebi Sep 30, 2018
db13ac3
Use zend_type_error() instead of zend_throw_exception_ex()
bwoebi Sep 30, 2018
a119939
Fix unsetting shadowed typed properties holding a reference
bwoebi Sep 30, 2018
f6209ee
Make all uninit access Error instead of TypeError & properly unmangle…
bwoebi Oct 1, 2018
5ae9a3f
Merge branch 'master' into typed_ref_properties
dstogov Oct 2, 2018
911e7c6
Merge branch 'master' into typed_ref_properties
dstogov Oct 2, 2018
d274d58
Fix test
bwoebi Oct 4, 2018
d34cddc
Merge branch 'master' into typed_ref_properties
nikic Oct 17, 2018
10151f1
Merge remote-tracking branch 'php-src/master' into typed_ref_properties
nikic Nov 22, 2018
e231c31
Some opcache fixes
nikic Nov 22, 2018
18fe3b0
Merge branch 'master' into typed_ref_properties
nikic Jan 2, 2019
21e405a
Initialize unserialize_data refs
nikic Jan 2, 2019
6a27224
Check for type violations through implicit object init
nikic Jan 3, 2019
25a517c
Handle the reference case as well
nikic Jan 3, 2019
cca6c1c
Remove incorrect string check, add tests
nikic Jan 3, 2019
373579c
Check for no type in "type_assignable" functions
nikic Jan 3, 2019
834c8d0
Merge branch 'master' into typed_ref_properties
nikic Jan 3, 2019
92cfec9
Improve auto-initialization related error messages
nikic Jan 3, 2019
ac1ac47
Extract auto-init errors into cold helpers
nikic Jan 3, 2019
0311fc5
Remove hardcoded path in test
nikic Jan 3, 2019
6574e7f
Handle all FETCH_OBJ flags in opcache
nikic Jan 3, 2019
d44a513
Fix static prop ref sources memory leak under opcache
nikic Jan 3, 2019
f95ef9c
Fix fastcall use on Windows
nikic Jan 3, 2019
c0f7ab6
Test tweaks
nikic Jan 3, 2019
3cdaf71
Remove unnecessary flag handling in compact_literals
nikic Jan 3, 2019
eec91a2
Remove unnecessary result undefing
nikic Jan 3, 2019
4efefc3
Add ASSIGN_STATIC_PROP to opcodes that can have unused result
nikic Jan 3, 2019
f6257b7
Pack obj fetch flags tighter, so it's compatible with 32 bit
nikic Jan 3, 2019
f28943c
Start working on inference support for typed static props
nikic Jan 3, 2019
4910f1d
Support type inference for static properties
nikic Jan 4, 2019
78acbd7
Don't call magic in ReflectionProperty::isInitialized()
nikic Jan 4, 2019
7430115
Remove redundant check in zend_inheritance
nikic Jan 4, 2019
c5d916f
Remove dead code
nikic Jan 4, 2019
8b71442
Convert if/else to switch
nikic Jan 4, 2019
401ff4c
Revert "Remove lchown($file, -5); test"
nikic Jan 4, 2019
dbf7d82
Allow references to typed properties during unserialization
nikic Jan 4, 2019
b1df1b7
Fix type checks during unserialization
nikic Jan 4, 2019
bac5425
Correctly handle refs on ASSIGN_OBJ fastpath
nikic Jan 7, 2019
882aaba
Handle ASSIGN_STATIC_PROP compound assign in SCCP
nikic Jan 7, 2019
9788344
Remove bogus check in ASSIGN_OBJ_REF
nikic Jan 7, 2019
c89b5ba
Add slot to prop info mapping mechanism
nikic Jan 7, 2019
40540b7
Fix ref source removal on object destruction
nikic Jan 7, 2019
9360955
Assert that all type sources have been removed when ref is dtored
nikic Jan 7, 2019
5f7d376
Use get_property_info_for slot while unsetting properties as well
nikic Jan 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Zend/tests/type_declarations/typed_properties_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
Test typed properties basic operation
--FILE--
<?php
var_dump(new class(1, 2.2, true, ["four"], new stdClass) {
public int $int;
public float $float;
public bool $bool;
public array $array;
public stdClass $std;
public iterable $it;

public function __construct(int $int, float $float, bool $bool, array $array, stdClass $std) {
$this->int = $int;
$this->float = $float;
$this->bool = $bool;
$this->array = $array;
$this->std = $std;
$this->it = $array;
}
});
?>
--EXPECTF--
object(class@anonymous)#%d (6) {
["int"]=>
int(1)
["float"]=>
float(2.2)
["bool"]=>
bool(true)
["array"]=>
array(1) {
[0]=>
string(4) "four"
}
["std"]=>
object(stdClass)#%d (0) {
}
["it"]=>
array(1) {
[0]=>
string(4) "four"
}
}

17 changes: 17 additions & 0 deletions Zend/tests/type_declarations/typed_properties_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test typed properties error condition (read uninitialized)
--FILE--
<?php
$thing = new class() {
public int $int;
};

var_dump($thing->int);
?>
--EXPECTF--
Fatal error: Uncaught Error: Typed property class@anonymous::$int must not be accessed before initialization in %s:6
Stack trace:
#0 {main}
thrown in %s on line 6


16 changes: 16 additions & 0 deletions Zend/tests/type_declarations/typed_properties_003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test typed properties error condition (fetch uninitialized by reference)
--FILE--
<?php
$thing = new class() {
public int $int;
};

$var = &$thing->int;
?>
--EXPECTF--
Fatal error: Uncaught Error: Cannot access uninitialized non-nullable property class@anonymous::$int by reference in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d

20 changes: 20 additions & 0 deletions Zend/tests/type_declarations/typed_properties_004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test typed properties error condition (type mismatch)
--FILE--
<?php
new class("PHP 7 is better than you, and it knows it ...") {
public int $int;

public function __construct(string $string) {
$this->int = $string;
}
};
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Typed property class@anonymous::$int must be int, string used in %s:6
Stack trace:
#0 %s(2): class@anonymous->__construct('PHP 7 is better...')
#1 {main}
thrown in %s on line 6


20 changes: 20 additions & 0 deletions Zend/tests/type_declarations/typed_properties_005.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Test typed properties error condition (type mismatch object)
--FILE--
<?php
class Dummy {}

new class(new Dummy) {
public stdClass $std;

public function __construct(Dummy $dummy) {
$this->std = $dummy;
}
};
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Typed property class@anonymous::$std must be an instance of stdClass, Dummy used in %s:8
Stack trace:
#0 %s(4): class@anonymous->__construct(Object(Dummy))
#1 {main}
thrown in %s on line 8
15 changes: 15 additions & 0 deletions Zend/tests/type_declarations/typed_properties_006.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Test typed properties inheritance (scalar)
--FILE--
<?php
class Foo {
public int $qux;
}

class Bar extends Foo {
public string $qux;
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8

19 changes: 19 additions & 0 deletions Zend/tests/type_declarations/typed_properties_007.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test typed properties inheritance
--FILE--
<?php
class Whatever {}
class Thing extends Whatever {}

class Foo {
public Whatever $qux;
}

class Bar extends Foo {
public Thing $qux;
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be Whatever (as in class Foo) in %s on line 11


16 changes: 16 additions & 0 deletions Zend/tests/type_declarations/typed_properties_008.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test typed properties inheritance (missing info)
--FILE--
<?php
class Foo {
public int $qux;
}

class Bar extends Foo {
public $qux;
}
?>
--EXPECTF--
Fatal error: Type of Bar::$qux must be int (as in class Foo) in %s on line 8


23 changes: 23 additions & 0 deletions Zend/tests/type_declarations/typed_properties_009.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Test typed properties unset leaves properties in an uninitialized state
--FILE--
<?php
class Foo {
public int $bar;

public function __get($name) {
var_dump($name);
/* return value has to be compatible with int */
return 0;
}
}

$foo = new Foo();

unset($foo->bar);

var_dump($foo->bar);
?>
--EXPECT--
string(3) "bar"
int(0)
17 changes: 17 additions & 0 deletions Zend/tests/type_declarations/typed_properties_010.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test typed properties allow fetch reference
--FILE--
<?php
class Foo {
public int $bar = 1;
}

$cb = function(int &$bar) {
var_dump($bar);
};

$foo = new Foo();
$cb($foo->bar);
?>
--EXPECT--
int(1)
18 changes: 18 additions & 0 deletions Zend/tests/type_declarations/typed_properties_011.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Test typed properties allow fetch reference for init array
--FILE--
<?php
class Foo {
public int $bar = 1;
}

$foo = new Foo();

$array = [&$foo->bar];
var_dump($array);
?>
--EXPECT--
array(1) {
[0]=>
&int(1)
}
19 changes: 19 additions & 0 deletions Zend/tests/type_declarations/typed_properties_012.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test typed properties allow fetch reference for foreach
--FILE--
<?php
class Foo {
public int $bar = 1;
}

$foo = new Foo();
foreach ($foo as &$prop) {
$prop++;
}
var_dump($foo);
?>
--EXPECT--
object(Foo)#1 (1) {
["bar"]=>
&int(2)
}
10 changes: 10 additions & 0 deletions Zend/tests/type_declarations/typed_properties_013.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Test typed properties disallow incorrect type initial value (scalar)
--FILE--
<?php
class Foo {
public int $bar = "string";
}
?>
--EXPECTF--
Fatal error: Default value for property of type int can only be int in %s on line 3
10 changes: 10 additions & 0 deletions Zend/tests/type_declarations/typed_properties_014.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Test typed properties disallow incorrect type initial value (array)
--FILE--
<?php
class Foo {
public array $bar = 32;
}
?>
--EXPECTF--
Fatal error: Default value for property of type array can only be an array in %s on line 3
10 changes: 10 additions & 0 deletions Zend/tests/type_declarations/typed_properties_015.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
Test typed properties disallow incorrect type initial value (object)
--FILE--
<?php
class Foo {
public stdClass $bar = null;
}
?>
--EXPECTF--
Fatal error: Default value for property of type stdClass may not be null. Use the nullable type ?stdClass to allow null default value in %s on line %d
19 changes: 19 additions & 0 deletions Zend/tests/type_declarations/typed_properties_016.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test typed properties initial values
--FILE--
<?php
class Foo {
public int $int = 1;
public float $flt = 2.2;
public float $flt2 = 2;
public array $arr = [];
public bool $bool = false;
public iterable $iter = [];
}
echo "ok\n";
?>
--EXPECT--
ok



12 changes: 12 additions & 0 deletions Zend/tests/type_declarations/typed_properties_017.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Test typed properties disallow void
--FILE--
<?php
class Foo {
public void $int;
}

$foo = new Foo();
?>
--EXPECTF--
Fatal error: Property Foo::$int cannot have type void in %s on line 3
17 changes: 17 additions & 0 deletions Zend/tests/type_declarations/typed_properties_018.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Test typed properties type applies to all props in group
--FILE--
<?php
class Foo {
public int $bar,
$qux;
}

$reflector = new ReflectionClass(Foo::class);

$prop = $reflector->getProperty("qux");

var_dump((string) $prop->getType());
?>
--EXPECT--
string(3) "int"
27 changes: 27 additions & 0 deletions Zend/tests/type_declarations/typed_properties_019.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Test typed properties int must not be allowed to overflow
--FILE--
<?php
class Foo {
public int $bar = PHP_INT_MAX;

public function inc() {
return ++$this->bar;
}
}

$foo = new Foo();

var_dump($foo->inc());
?>
--EXPECTF--
Fatal error: Uncaught TypeError: Typed property Foo::$bar must be int, float used in %s:6
Stack trace:
#0 %s(12): Foo->inc()
#1 {main}
thrown in %s on line 6





26 changes: 26 additions & 0 deletions Zend/tests/type_declarations/typed_properties_020.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Test typed properties binary assign op helper test
--FILE--
<?php
declare(strict_types=1);

class Foo {
public int $bar = 0;

public function __construct() {
$this->bar += 2;
try {
$this->bar += 1.5;
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
}
}

$foo = new Foo();

var_dump($foo->bar);
?>
nikic marked this conversation as resolved.
Show resolved Hide resolved
--EXPECT--
Typed property Foo::$bar must be int, float used
int(2)
Loading