Req #81338 [Opn->Nab]: readonly properties cannot be used with iterators
| From: | nikic@php.net | Date: | Fri, 06 Aug 2021 13:53:02 +0000 |
| Subject: | Req #81338 [Opn->Nab]: readonly properties cannot be used with iterators | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235649@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81338&edit=1
ID: 81338
Updated by: nikic@php.net
Reported by: julien dot boudry at gmail dot com
Summary: readonly properties cannot be used with iterators
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: *General Issues
Operating System: All
PHP Version: 8.1.0beta2
Block user comment: N
Private report: N
New Comment:
Modifying IAP is still a modification, so declining this feature request.
Generally, I would recommend to never use the IAP and instead use either ArrayIterator or
generators.
Previous Comments:
------------------------------------------------------------------------
[2021-08-06 13:42:01] julien dot boudry at gmail dot com
Description:
------------
https://3v4l.org/edgYU/rfc#vgit.master
Internal array pointer can not be modified for readonly properties.
This strongly limits the possibility of implementing Iterator interfaces using them. The following
example is simpler, but still follows the same principle.
These properties would be much more useful if the pointer remained free, as the data itself is not
impacted.
Test script:
---------------
<?php
class A {
public function __construct (public readonly array $ary = [0,1,2,3]) {}
}
$obj = new A;
var_dump(current($obj->ary));
next($obj->ary);
var_dump(current($obj->ary));
Expected result:
----------------
int(0)
int(1)
Actual result:
--------------
int(0)
Fatal error: Uncaught Error: Cannot modify readonly property A::$ary in /in/CBCan:12
Stack trace:
#0 {main}
thrown in /in/CBCan on line 12
Process exited with code 255.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81338&edit=1