Skip to content

Commit

Permalink
count.xml Amend the code example and add return type (#4291)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mmalferov authored Dec 12, 2024
1 parent b37bddf commit 527e9b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions language/predefined/countable/count.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@
<programlisting role="php">
<![CDATA[
<?php
class Counter implements Countable {
class Counter implements Countable
{
private $count = 0;
public function count() {
public function count(): int
{
return ++$this->count;
}
}
Expand All @@ -51,6 +54,7 @@ $counter = new Counter;
for ($i = 0; $i < 10; ++$i) {
echo "I have been count()ed " . count($counter) . " times\n";
}
?>
]]>
</programlisting>
Expand Down

0 comments on commit 527e9b1

Please sign in to comment.