Skip to content

Commit 3f2012f

Browse files
committed
Problem file
1 parent a7e8881 commit 3f2012f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
You have been given a piece of code (look for `the-return-of-static.php` in your working directory) which is using static return types.
2+
3+
You will find two classes. `File`, a base class, and `Image` a class extending and adding behavior to `File`. We instantiate `Image`, set some properties using a fluent interface and then dump the object using `var_dump`.
4+
5+
If you run the code using `{appname} run the-return-of-static.php` you will see it is broken.
6+
7+
Locate and fix the issue!
8+
9+
### The advantages of the static return type
10+
11+
* Enforces that an instance of the class the method is called from, is returned.
12+
* Most useful for fluent interfaces and static constructors to ensure an instance of a parent class is not returned.
13+
14+
----------------------------------------------------------------------
15+
## HINTS
16+
17+
(Brief) Documentation on the static return type feature can be found by pointing your browser here:
18+
[https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.static]()
19+
20+
The static return type enforces methods to return an instance of the class that the method was called from, rather than the one it was defined in.
21+

0 commit comments

Comments
 (0)