Skip to content

Commit 527e9b1

Browse files
authored
count.xml Amend the code example and add return type (#4291)
Return type of Counter::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
1 parent b37bddf commit 527e9b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

language/predefined/countable/count.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@
3838
<programlisting role="php">
3939
<![CDATA[
4040
<?php
41-
class Counter implements Countable {
41+
42+
class Counter implements Countable
43+
{
4244
private $count = 0;
4345
44-
public function count() {
46+
public function count(): int
47+
{
4548
return ++$this->count;
4649
}
4750
}
@@ -51,6 +54,7 @@ $counter = new Counter;
5154
for ($i = 0; $i < 10; ++$i) {
5255
echo "I have been count()ed " . count($counter) . " times\n";
5356
}
57+
5458
?>
5559
]]>
5660
</programlisting>

0 commit comments

Comments
 (0)