File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ --TEST--
2+ A convoluted path
3+ --FILE--
4+ <?php
5+
6+ data class Length {
7+ public function __construct (public float $ length ) {}
8+ }
9+
10+ data class Point {
11+ public int $ x ;
12+ private Length $ l ;
13+ public function __construct (int $ x , public int $ y ) {
14+ $ previous = $ this ;
15+ $ this ->x = $ x ;
16+ $ this ->l = new Length ($ x + $ y );
17+ echo "$ previous === $ this \n" ;
18+ }
19+
20+ public function addNoisily (Point $ other ): Point {
21+ echo "Adding $ this and $ other \n" ;
22+ $ previous = $ this ;
23+ $ this ->x += $ other ->x ;
24+ $ this ->y += $ other ->y ;
25+ $ this ->l = new Length ($ this ->x + $ this ->y );
26+ echo "$ previous !== $ this \n" ;
27+ return $ this ;
28+ }
29+
30+ public function __toString (): string {
31+ return "( {$ this ->x }, {$ this ->y }| {$ this ->l ->length }) " ;
32+ }
33+ }
34+
35+ $ p1 = new Point (1 , 2 );
36+ $ p2 = $ p1 ->addNoisily ($ p1 );
37+
38+ ?>
39+ --EXPECT--
40+ (1,2|3) === (1,2|3)
41+ Adding (1,2|3) and (1,2|3)
42+ (1,2|3) !== (2,4|6)
You can’t perform that action at this time.
0 commit comments