php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78337 Typed properties references inconsistency due to gc
Submitted: 2019-07-27 12:52 UTC Modified: 2019-07-27 13:28 UTC
From: jascha dot php at ja-s dot de Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.4.0beta1 OS:
Private report: No CVE-ID: None
 [2019-07-27 12:52 UTC] jascha dot php at ja-s dot de
Description:
------------
I've just looked into PHP 7.4s property typing. I'm a little disappointed, that this is currently limited to properties, and can not be applied to any variables.

Luckily v2 supports references to properties. So I'm pretty sure somebody is gonna provide a little library to construct typed variables by linkin a variable to the reference set of a typed property.

But what isn't mentioned in the typed_properties_v2 RFC, is how the garbage collector affects the typing due to reducing the reference set. This can produce unexpected behavior.


Possible solutions:
* Forbid references: https://wiki.php.net/rfc/typed_properties_v2#forbid_references
* Add typed variables (seems unlikely, but i'm hoping for this)
* Just document the behavior

Test script:
---------------
https://3v4l.org/ctEgn

Expected result:
----------------
string(3) "123"
string(3) "123"

Actual result:
--------------
int(123)
string(3) "123"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-27 13:28 UTC] nikic@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2019-07-27 13:28 UTC] nikic@php.net
This is by design and discussed extensively in the RFC.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 10:01:30 2024 UTC