Arnaud Le Blanc

PHP

Support group for those afflicted with PHP. Don't ask to ask, ...
Apr 7 22:12
@IluTov a solution to that, and to the non-ref cycle problem, would be to return true for arrays in may_cause_cycle(). This way "a" is considered possibly cyclic in your example. This will consider more arrays as possibly cyclic, but this may still be beneficial. Otherwise it is required to propagate flag changes to parents, maybe on the fly in FETCH_DIM_W if the op is aware of the value being assigned.
Apr 7 21:55
@IluTov I see what you mean. You could also remove the NOT_COLLECTABLE flag of an array when storing it in a reference, but you need to do that when storing in an object as well
Apr 7 19:50
@IluTov Yes that's the issue. We will miss garbage cycles if we don't add possibly-cyclic values to the buffer after a decref. We need to track which arrays may be cyclic, but that's basically github.com/php/php-src/pull/9979
Apr 2 13:23
@IluTov with the same technique as in github.com/php/php-src/pull/9979, we may be able to flag arrays containing references, so that only those need to be handled
Apr 2 12:55
@IluTov Yes! May we take the opportunity to fix this in data classes?
Apr 2 12:52
@IluTov I think they are also a problem in arrays. The issue is that you can not just store an array/data class an assume it will not be modified later by the user, as they may hold references to members of the array/data class
Apr 2 12:25
Since using ! is required when calling mutating methods, can we make it part of the actual method name and remove the mutating keyword? E.g. function append!()
Apr 2 12:25
Do you have an idea of how this will interact with hooks? Hooks deny $o->prop[$offset]=...; will the same restriction apply when calling mutating methods? E.g. will $o->prop->append!() be allowed if $o->prop is hooked?
Apr 2 12:24
Currently this allows to acquire references to data class props, but this defeats CoW. Should this be denied?
Apr 2 12:24
https://github.com/php/php-src/pull/13800 @IluTov

I like the idea!

Some thoughts:
Mar 15 20:38
@MarkR BTW, runtime checks aside, what would be the benefits of an official static analyzer when compared to phpstan/psalm?
Mar 15 20:30
I see at least two challenges with this approach:
1. Enabling previously disabled type checks can be a breaking change because of coercion (although the inverse would be a bigger issue)
2. The type system would need to be designed with the VM/compiler in mind, otherwise it may never be possible to integrate it (because of performances). And even then, flaws could be found during the integration and it may be too late to fix them (because of BC)
Mar 15 20:13
@Trowski TS is different in that it is fully erased and there is no runtime types. f(v) infers T from the static type of v, which almost always results in what the programmer wants. What I meant is that inferring T from the runtime type of v would more often not.
Mar 15 19:43
using the runtime type for function calls can be an issue if the function uses the type at runtime like f<T>(t: T) { return new List<T>() }, as T may be too specific
Mar 15 19:30
@Crell $l = new List<Product> is verbose especially when you have multiple type arguments and you need to type this repeatedly. This also applies to functions: array_map has 3 types args (key type, original value type, new value type) and specifying them is super verbose: array_map<int,Foo,Bar>($cb, $ary).
Mar 15 17:04
@Crell The only purpose of allowing it is to reduce verbosity I think. Rust lets you create a Vec without specifying upfront what will be in it, yet it's safe: play.rust-lang.org/…. In @bwoebi's idea, if the type changes internally but it behaves as if it had the actual type from the start, and if the types could be discovered statically, this seems fine to me
Mar 15 15:16
@LeviMorrison could you elaborate on how it would help? I'm genuinely curious
Mar 15 15:08
@Crell $a = [1, 'beep']; f($a);: this can be spotted by a static analyzer in this flavor of generic arrays (this is how it's implemented in phpstan and psalm)
Mar 15 15:04
that's interesting. So, passing arguments to the object widens requires-types, and passing the object narrows permitted-types. It could be static analyzer friendly but only if the latter could be narrowed only once, I think:
```
function g(container<A|B>) {}
function f(container<A|B|C> $obj) { g($obj); }
f($obj)
$obj->push(new C);
```
Otherwise, $obj is container<req(A|B),perm(A|B)> after calling f, but a static analyzer is not able to infer that, and can't say that the last line is unsafe.
Mar 12 20:14
@bwoebi Investigating this is on my todo list, but the challenges around performance are the same. The work I did can be used as a foundation for both styles of type inference, so it's possible to try both
Dec 20, 2022 16:00
@A.B.Carroll I would say it is, because instructions take input/output operands and do not push/pop from the stack. Even though temporaries live on the stack
Oct 7, 2022 10:31
Any thoughts on github.com/php/php-src/pull/9104 ? (before I write to internals)
Oct 3, 2022 17:59
> Modules are supposed to be able to be dynamically sized
Because of zend_module_entry.size?
Jul 2, 2022 08:52
@LeviMorrison do you mean to allow & before variables in assignment, like fn () { &$a = 1; } ?
Jun 5, 2022 17:24
I think that the zend_test extension defines a backed enum
Jun 4, 2022 23:11
What else if broken in arrays currently in your opinion?
Jun 4, 2022 23:01
I like arrays though :D Having a native LinkedHashMap in the language is really great for many tasks. Fixing key the coercion problem and adding the list and map types as specializations of arrays would be perfect. And array shapes.
Jun 4, 2022 22:56
This would be really great
Jun 4, 2022 22:49
@MarkR I wonder if generic arrays could be an opportunity to fix the numeric string key coercion as well. E.g. an array<string,Foo> wouldn't coerce keys. Could be practicable as long as the type is explicitly specified.
Jun 3, 2022 19:03
@Crell Oh I see. Yes we should try to do that
Jun 3, 2022 19:00
@Danack I think that the Makefile rule %_arginfo.h: %.stub.php will run if the .php is more recent than the .h
Jun 3, 2022 18:54
@Crell we can definitely make a lot of ground work without changing the language, but I don't know if merging this change before an RFC is accepted is a good idea
Jun 3, 2022 18:19
@sj-i I want to work on that some day
Jun 3, 2022 18:19
@Crell That would help, but then we need generic functions to work with these generic collections :D
Jun 3, 2022 18:14
@sj-i yes! assert() is a good alternative except for generics
Jun 3, 2022 17:08
This is a problem in expressions like new Collection(). The analyzer has nothing to infer the type parameters here. If PHP had generics natively we could write new Collection<int>() in this case.
Jun 3, 2022 17:03
*instantiation or function call
Jun 3, 2022 17:00
Psalm/PHPStan/PHPStorm would most benefit from a native generics syntax. Especially, in Psalm/PHPStan it is not possible to specify type parameter during instantiation of function call because there is no syntax for it. So Psalm/PHPStan need to rely entirely on parameter inference.
Jun 3, 2022 11:59
@Crell I definitely want to put the RFC forward soon. I want to try to address some feedbacks first
May 28, 2022 10:04
@IluTov Ah, thank you. At least there is some determinism, then :D
May 28, 2022 09:51
(replying to @IMSoP) (I don't know why sometimes the reply feature will @, and sometimes it will not)
May 28, 2022 09:49
Thank you for this summary. A general feeling I had when reading these threads is that many concerns are about problems that would exist only if capture was by-ref or by-val. Cited issues include side-effects, global-like behavior, javascript headaches.

Should we insist more on the fact that capture is by-value, and the problems that exist in javascript for example would not exist here ?
May 25, 2022 20:10
Explicit capture by-ref can be useful because we can't auto-capture by-ref. People would have to switch back to long closures when they need to capture by-ref, otherwise. Explicit capture by-val is supported mostly for consistency and because it uses the same grammar as long closures for this part. It can be useful when the function has var-vars though, because var-vars don't capture (like in arrow functions).

I will expand on variable capture
May 25, 2022 19:43
@bwoebi Agreed :)
May 25, 2022 18:57
```
fn () use ($a, &$b) {
$b = $a + $c;
}
```
captures $a by-val, $b by-ref, $c by-val
May 25, 2022 18:55
Yes
It will capture all variables that may be read by the function + any variable specified in use() (by-ref and by-val)
May 25, 2022 18:53
Thank you!

In "variables defined within an auto-capturing long closure that are also defined externally to the closure will be captured by value", it would be more accurate to say that "variables that may be read within" or "variables that may be used" instead of "variables defined"

In the section "What about long-closures?", the two bullet points are not longer true. The new patch supports the use() syntax, mostly for the purpose of capturing by reference
May 25, 2022 17:11
Morning

When reviving/pursuing an RFC that has already been discussed a while ago but not voted, should we reuse the RFC, or create a new one ? I'm asking this in the context of https://wiki.php.net/rfc/auto-capture-closure. Original authors Nuno and Larry are comfortable with reusing the origin code and RFC (their names will be on the authors list in any case).
May 20, 2022 09:06
Morning
I've been continuing Nuno's work on auto-capturing closures: https://github.com/php/php-src/pull/8330
Any thoughts before I move to internals and update the RFC ?
May 16, 2022 08:39
@LeviMorrison it may be that SIG globals are freed before zend_signal_deactivate is called, so SIGG(depth) is accessing freed memory here in ZTS. What does the stack trace look like in NTS ?