note 127109 added to class.iterator
| From: | Zeomni at main dot php dot net | Date: | Tue, 17 May 2022 08:09:54 +0000 |
| Subject: | note 127109 added to class.iterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218480@lists.php.net to get a copy of this message | ||
WARNING : due to new PhP 8 feature, "internal method return type"
Example of the documentation and All comment before 2022 on this page are raising some Deprecated
warning, or fatal error on PhP 9.0
You now have to type all your return implementation:
Example for key() you must add ": mixed", else it will raise on PhP8.1 :
Return type of myIterator::key() should either be compatible with Iterator::key(): mixed, or the
#[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice.
<?php
public function key(): mixed {
var_dump(__METHOD__);
return $this->position;
}
?>
Please note the adding the [#\ReturnTypeWillChange] is not a long term solution, as PhP 9.0 will
raise a fatal and not a warning.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.47 (proxied: 87.98.137.70)
----
Manual Page -- https://php.net/manual/en/class.iterator.php
Edit -- https://main.php.net/note/edit/127109
Del: integrated -- https://main.php.net/note/delete/127109/integrated
Del: useless -- https://main.php.net/note/delete/127109/useless
Del: bad code -- https://main.php.net/note/delete/127109/bad+code
Del: spam -- https://main.php.net/note/delete/127109/spam
Del: non-english -- https://main.php.net/note/delete/127109/non-english
Del: in docs -- https://main.php.net/note/delete/127109/in+docs
Del: other reasons-- https://main.php.net/note/delete/127109
Reject -- https://main.php.net/note/reject/127109
Search -- https://main.php.net/manage/user-notes.php