Skip to content

Commit

Permalink
Simplify Stringable example with PHP 8 syntax (#3514)
Browse files Browse the repository at this point in the history
Stringable is introduced in PHP 8.0, so constructor
promotion can be assumed.
  • Loading branch information
Krinkle authored Jul 7, 2024
1 parent 1ad4e2d commit 3e519f4
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions language/predefined/stringable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,20 @@
<![CDATA[
<?php
class IPv4Address implements Stringable {
private string $oct1;
private string $oct2;
private string $oct3;
private string $oct4;
public function __construct(string $oct1, string $oct2, string $oct3, string $oct4) {
$this->oct1 = $oct1;
$this->oct2 = $oct2;
$this->oct3 = $oct3;
$this->oct4 = $oct4;
}
public function __construct(
private string $oct1,
private string $oct2,
private string $oct3,
private string $oct4,
) {}
public function __toString(): string {
return "$this->oct1.$this->oct2.$this->oct3.$this->oct4";
}
}
function showStuff(string|Stringable $value) {
// A Stringable will get converted to a string here by calling
// __toString.
// For a Stringable, this will implicitliy call __toString().
print $value;
}
Expand Down

0 comments on commit 3e519f4

Please sign in to comment.