« first day (3861 days earlier)      last day (1077 days later) » 

8:00 PM
Why can't ReflectionFunction simply accept a Partial (and only expose the usual ReflectionFunction funtionality on it)?
You can have additional functionality on ReflectionPartial
 
@NikiC It was because fromCallable() just returns a Callable as is, which Partials were. HOWEVER, Because Reflection(tm), a Partial needed to use ReflectionPartial, whereas a Callable uses ReflectionFunction, and there is no ReflectionClosure.
 
@Crell if PHP was thinking 10 years ahead from the start we wouldn't have function names based on their hash length :P
 
@MarkR Touche...
 
Though I should say that similar to Fiber + ReflectionFiber, I think that you might just want to add certain reflection functionality directly on the Partial class, rather than requiring the construction of a wrapper
@Crell I think I'm missing the "Because Reflection(tm)" part
 
@NikiC That's a question for @JoeWatkins. :-)
 
8:01 PM
$foo->bar(?) is equivalent to making a function (/*whatever signature $foo->bar has */): /*whatever return type $foo->bar has */ { return $foo->bar(... /*apply all args */); } and the scope is bound to... the current scope I think?
 
(I am repeating what he said 3 hours ago, mainly. If he wakes up he can give a better answer.)
 
I understand that we can't (or at least shouldn't) expose Partial-specific functionality in ReflectionFunction, but it should still support it just fine
 
Maybe we can actually try doing tree-rewriting ? Ah no we can't. I remember now, we don't know the signature.
 
The implementation intricacies of reflection are above my pay grade, sorry. This is a Joe question.
 
@LeviMorrison That wouldn't carry over types etc
 
8:03 PM
Yeah, I remembered ^_^
 
So I googled PHP fibers and ended up at php-fibers.com mmmmmkay
 
We could theoretically rewrite it to a series of reflection calls that in the end evals code? Ahahaha
 
How is $foo->bar(?) different from fn($value) => $foo->bar($value)?
 
But, that's what we're doing, just in the engine...
 
As in, fn($value) => $foo->bar($value) has bind, bindTo, etc.
 
8:05 PM
@Trowski The type and ref-ness of the args and the return get propagated.
 
Ok fine, so different from fn(ParamType $value): ReturnType => $foo->bar($value)
 
It also stacks additional args on the end
 
? also doesn't bind a single arg, so it would have whatever args bar has, not just one.
 
Yes, yes, but fundamentally it is sugar for declaring a short closure, no?
 
@Gordon Wat?
 
8:08 PM
$foo->bar(?, 'value', ?) is equivalent to fn (ParamType1 $value1, ParamType3 $value3): ReturnType => $foo->bar($value1, 'value', $value3)
 
@Trowski For the typical user case, as viewed from the user, yes. As an actual implementation, no. (I think that's part of what's confusing.)
 
My point is that the implementation, in theory, should be able to effectively make that closure based on the $foo->bar(?, 'value', ?);
I'd have to really dive in to see how that's possible. This is more directed at @NikiC and @JoeWatkins.
 
That's what I expected to happen, but Joe had reasons for doing otherwise that were over my head, and I wasn't in a position to question him. :-) I'm just the secretary, as usual.
 
@Crell the website says: PHP Fibers has production facilities in Germany, the US and China. The company was established in 1899 and is now the largest manufacturer of Nylon 6.6 for the airbag industry in Europe and a leading producer of PA yarns for tires and other MRG applications.
 
And I'm the one with just enough internals knowledge to get myself in trouble, lol
 
8:11 PM
So I guess the starred message about PHP fibres making a sweater isn't too far off :D
 
@Gordon The RFC is the #2 result. I anticipate the results to change in a short time.
 
krakjoe@Fiji:/opt/src/php-src$ cat test.php
<?php
class Foo implements Invokable {
    public function __invoke() {}
}

var_dump(new Foo instanceof Invokable);

class Bar {
    public function __invoke() {

    }
}

var_dump(new Bar instanceof Invokable);

var_dump(sprintf(?) instanceof Invokable);

var_dump(function(){} instanceof Invokable);
?>
krakjoe@Fiji:/opt/src/php-src$ sapi/cli/php test.php
bool(true)
bool(true)
bool(true)
bool(true)
 
Yes, but @Joe, __invoke can have arguments and a return type.
 
@Trowski for me it was the fifth result, but I agree.
 
@JoeWatkins Though I see you have sprintf(?) working, interesting.
 
8:14 PM
well that doesn't actually show what Invokable is, if it has __invoke or not
 
@MarkR Touché
 
krakjoe@Fiji:/opt/src/php-src$ cat test.php
<?php
class Foo implements Invokable {
    public function __invoke() {}
}

var_dump(new Foo instanceof Invokable);

class Bar {
    public function __invoke(int $arg) : array {

    }
}

var_dump(new Bar instanceof Invokable);

var_dump(sprintf(?) instanceof Invokable);

var_dump(function(){} instanceof Invokable);

class Qux implements Invokable {

}
?>
krakjoe@Fiji:/opt/src/php-src$ sapi/cli/php test.php
bool(true)
bool(true)
bool(true)
bool(true)
 
Awesome.
 
@Crell @LeviMorrison are we on board ?
 
@JoeWatkins Can you explain why the implementation isn't doing essentially this: chat.stackoverflow.com/transcript/message/52187042#52187042
 
8:19 PM
Um. So let me make sure I follow.

Invokable becomes a new internal only interface that means "has __invoke on it, but with any signature." It gets magically added to Closure, Partial, and any class that happens to have an __invoke on it.

I'm OK with it. I'm still lost as to what benefit it brings us, since I don't expect callable or callable strings/arrays to disappear any time soon, but I'm OK with it. :-)
 
They'll disappear if we remove them from the language :P
 
I am still not convinced we can.
 
`var_dump('strtoupper' instanceof Invokable);`
What should that output?
 
@JoeWatkins Can you confirm (or point me to where my novice eyes could figure out) what other methods are on ReflectionPartial? Like, can we decompose back out the original callable?
 
Logically, false. Semantically, true.
 
8:21 PM
@JoeWatkins Well... I was on board. Now Nikita has me second-guessing. Maybe your Partial extends Closure version was actually better. Bleh. Sorry for the flip-flopping, but I think I had logical reasons for both flip and flop! Will do more thinking about it.
 
Even if partial extends closure, something with __invoke wouldn't extend closure.
 
@NikiC Quick thought: can we change the concrete type of closure literals to be RebindableClosure or something which extends (or inherits but that's more change for not sure what gain) from Closure, and then we have Partial extend closure, and some other type for what Closure::fromCallable creates? Goal is to have it be safe to call bind at the type-level iff $closure instanceof RebindableClosure.
 
@Sara false because Invokable is for objects. The idea is to transition anything invokable to be an object.
 
Ideally Closure would not have bind and only the concrete RebindableClosure would, but we need to compat with what we have to a degree.
Having Partials not work with Closure type checks would be really unfortunate.
 
So you'd have to use var_dump(strtoupper(?) instance of Invokable); bool(true)
 
8:25 PM
@Trowski I am slightly concerned about the performance impact of that. Although I have no idea if there is a performance difference in practice.
 
@Trowski essentially, why don't we create a closure ...
 
@JoeWatkins Essentially, yes.
 
@LeviMorrison Technically at least, that should be possible.
 
@Trowski Counterargument: Stringable
 
Though as a said before, bindTo() not working on all closures is something that's already true right now, so I'm not sure it's really a problem that needs solving
But if we do want to solve it, then yes, what you said should work (disclaimers apply)
 
8:26 PM
@NikiC Right, I was trying to fix that while adjusting other stuff in this space.
 
@Sara Elaborate, I don't follow.
@Crell Not having to check if a string|array is callable may negate the performance impact.
 
Remind me what the problems were with the previous Partial extends Closure design? I remember something about reflection... was there anything else?
 
'ClassName::methodName' is particularly not nice.
 
@LeviMorrison AFAIK, just the reflection complication.
 
@Crell Okay, and that complication was... what, exactly?
 
8:30 PM
@CharlesSprayberry that was my thought, yes
 
That it meant Closure::fromCallable() no longer worked as universal way to normalize callables into a single format for reflection.
 
@Crell More elaboration, please?
 
@kelunik Yea I like the idea. I'm all about being explicit and immutable and it seems like it would add both of those things. Would there be checks on a Provider making objects of the correct type? i.e. do we guard against your provider returning an object that is not a type in getTypes()?
 
33 mins ago, by Crell
@NikiC It was because fromCallable() just returns a Callable as is, which Partials were. HOWEVER, Because Reflection(tm), a Partial needed to use ReflectionPartial, whereas a Callable uses ReflectionFunction, and there is no ReflectionClosure.
 
@CharlesSprayberry not sure on that. Not doing it allows to have a provider that creates objects / values, but without offering them for type based autowiring
 
8:35 PM
@Crell Can we use ReflectionFunction?
 
@kelunik A Provider could create non-object values?
 
I understand it won't be as "rich" -- that's okay.
 
That's a Joe question. As of the last time I tested it, it actively exceptioned. Whether it's possible/feasible/good to do otherwise, I am the wrong person to ask. :)
 
@CharlesSprayberry yes, the context can keep any value as in PSR-11
 
@Danack No worries. Same here.
 
8:37 PM
@kelunik hrmmm.... I need to review PSR-11 again I think. It has been a minute since I looked over it... I use Auryn almost exclusively in my own projects so never really interacted with a PSR container before. Maybe once
 
@CharlesSprayberry same here, but it's useful, as you can just put your config values in there, too, and reference them by name in your definitions
 
PSR-11 is a nice and small spec. :-)
 
@kelunik hrmm.... perhaps. Need to start with just wrapping my head around the idea that an ~~injector~~ Context can do more than just objects.
 
@Crell I'd say largely incomplete. It says don't use it as service locator, but the only interface it specifies is that of a service locator
 
@JoeWatkins so something like: youtube.com/… nsfw audio.
 
8:47 PM
sorry, I'm not ignoring anyone ... code
 
@CharlesSprayberry I still need to think about the application lifecycle. I want to offer startup / shutdown functionality, but not sure whether there needs to be built in support of whether that can be completely separate.
 
@JoeWatkins I have some tests to push up to you, including 2 new fails I found. Safe to do so?
 
krakjoe@Fiji:/opt/src/php-src$ cat test.php
<?php
$partial = sprintf(?, 42);

echo $partial("Hello World %d\n");

var_dump($partial instanceof Closure);
var_dump($normal = Closure::fromCallable($partial));

$normal("Hello World %d\n");

var_dump(new ReflectionFunction($partial),
         new ReflectionFunction($normal));
?>
krakjoe@Fiji:/opt/src/php-src$ sapi/cli/php test.php
Hello World 42
bool(true)
object(Closure)#1 (1) {
  ["args"]=>
  array(2) {
    ["format"]=>
    NULL
    ["values"]=>
    int(42)
 
@kelunik Interesting. What were you thinking the use cases for that would be? Seems like it might be too many responsibilities
 
@JoeWatkins This is reporting the reflection info of the function being applied?
 
8:57 PM
<?php
$partial = sprintf(?, 42);

echo $partial("Hello World %d\n");

var_dump($partial instanceof Closure);
var_dump($normal = Closure::fromCallable($partial));

$normal("Hello World %d\n");

var_dump($partialFunction = new ReflectionFunction($partial),
         $normalFunction = new ReflectionFunction($normal));

var_dump($partialFunction->getParameters(), $normalFunction->getParameters());

echo $normalFunction->invokeArgs(["Hello World %d\n"]);

echo $partialFunction->invokeArgs(["Hello World %d\n"]);
 
Not quite understanding what I'm seeing.
 
Hello World 42
bool(true)
object(Closure)#1 (1) {
  ["args"]=>
  array(2) {
    ["format"]=>
    NULL
    ["values"]=>
    int(42)
  }
}
object(ReflectionFunction)#2 (1) {
  ["name"]=>
  string(7) "sprintf"
}
object(ReflectionFunction)#3 (1) {
  ["name"]=>
  string(7) "sprintf"
}
array(1) {
  [0]=>
  object(ReflectionParameter)#4 (1) {
    ["name"]=>
    string(6) "format"
  }
}
array(1) {
  [0]=>
  object(ReflectionParameter)#5 (1) {
    ["name"]=>
    string(6) "format"
  }
}
Hello World 42
Hello World 42
 
cmb
right; and then the bundled libmagic would need to be updated (bundled libmagic is [heavily patched](https://github.com/php/php-src/blob/master/ext/fileinfo/libmagic.patch))
Support for getimagetype() and friends needs to be implemented in https://github.com/php/php-src/blob/master/ext/standard/image.c. @BenMorss
 
@cmb That's just what I'm turning to now! Once you figured out the build issue, the AVIF encoding and decoding functions worked pretty quickly 🤯
 
cmb
:)
 
9:10 PM
@CharlesSprayberry there needs to be some owner of the singletons that is also responsible for shutting them down. The use case is, well, a clean application shutdown
In our application there's an in-memory mail sending queue for example. On shutdown this queue gets written to disk and the server process only stops after the queue is written to disk.
 
@kelunik What does "shutting them down" mean? I presume destroying the reference the container is holding?
 
9:33 PM
@JoeWatkins Back from a phone call. Bad timing. So, um, what are we seeing here? You managed to solve all the world's problems? :-)
 
yes
 
So, tldr, where do we land? (In enough detail that Nikita's OK with it and I can describe it in prose.)
 
unfortunately you are flying Ryanair, so you land roughly 200 miles from where you wanted to be, connected by a train which is actually a replacement bus service
 
and the bus you have to pedal with your feet?
 
wrong chat window but I'm totally leaving it there I can't believe how well that works
btw, Half Man Half Biscuit correctly point out that should actually be a replacement train service
oh and if anyone receives a scam SMS message can you send it to me somehow? specifically interested in the domains used in the URL
2
datetime, originating number, link is what I want
if you can be arsed <3
(international)
if you wanna just forward it to me I haven't changed my number :-P
 
9:52 PM
@JoeWatkins So what all changed? And do you want me to push up these tests?
 
@DaveRandom Weirdly enough never had any issues with Ryanair
 
I don't think I have ever flown with them but I would definitely have a bad time because I am 6'5" and easyjet is bad enough
I think I have come to believe that such things should not exist though, as much as I like things being available "to the masses" it's not worth the environmental cost
it should be expensive to fly
 
function volume(int $x, int $y, int $z): int {
    return $x * $y * $z;
}

class Resolver {
    private array $context = ['x' => 3];

    public function resolve(callable $c) {
        $f = new ReflectionFunction(Closure::fromCallable($c));
        $params = $f->getParameters();
        $parameters = array_map(fn(ReflectionParameter $r) => $r->getName(), $params);
        $args = array_intersect_key($this->context, array_flip($parameters));

        return $c(?, ...$args);
    }
}

$r = new Resolver();
Holy shit, that works!
 
like I should not be able to afford it
 
@Crell sorry, nearly there then can do words
 
10:00 PM
@JoeWatkins OK. I know it's getting late for you so I just want to make sure the loops are closed before you pass out. :-)
 
like 500 inappropriate jokes redacted ^^
 
@Crell When are you opening the vote?
 
@Crell no mo reflection partial
no more Partial objects in userland, it's a magic closure
 
@IluTov Given the changes happening right now, not until next week I expect.
Oh my.
 
@DaveRandom plong
 
10:06 PM
@Crell Oh ok, I just sure if it opens soon and I have to hurry up reading it properly.
 
@IluTov I'd say wait for me to post an update after today because stuff is changing, but then give it a read ASAP.
 
Are we back to partials being callables, with or without Invokables?
 
I dunno, I'm lost. :-)
 
no invokables, not required anymore ...
 
So... a partial is just a Closure object with extra black magic inside, nothing else changes (relative to 8.0)?
 
10:09 PM
But then how could something with __invoke pass the same check ?
 
@Crell yes
see test changes
 
@JoeWatkins <GeorgeTakei>Oh my</GeorgeTakei> OK, so I should pull and then sort out my test changes locally, then push the result?
 
please do
 
@Tiffany poing
 
so I think that solves all problems ...
 
10:13 PM
We'll see if it also fixes the new test fails I found.
 
@Crell They're becoming Closures right? Is that the only change?
Yep, I should read all the messages before commenting :)
 
@JoeWatkins So you completely killed the Partial class?
 
@JoeWatkins OK, pushed. The new tests include a segfault and a destructor behavior that Nikita said shouldn't happen. If you want to disagree with him, update the test accordingly. :-)
 
@Trowski it dies in the next commit
 
10:30 PM
Should I start updating the RFC then?
 
yeah
it's gone ...
now, what exactly is the compelling reason to support object constructors at all, before I spend any time on this, and while I drink my tea ?
 
object constructors?
 
I dunno; you had a test for it already. :-)
I mean it's... kinda neat? Might be nice for DI tools? I'm pretty sure that's where Nicolas was going with his line of questions.
Does the new approach still flatten repeated partialing?
 
yeah
 
@JoeWatkins Very awesome. Constructors as partials… if it's easy, fine, if not that's not a deal-breaker IMO.
 
10:35 PM
Spiffy.
It already works, but there's a caveat in the exception-in-constructor case.
 
@JoeWatkins Consistency, mostly. For most people it's not evident why features work in some places but not in others.
 
Object construction is more than just a function call, so I can see why it wouldn't be supported.
 
@Crell static public triggered. Aren't you a member of php-fig? :P
 
@IluTov I never liked PSR-2/12 anyway.
RFC updated. Please confirm I didn't confuse anything: wiki.php.net/rfc/partial_function_application
 
--TEST--
Partial with no arguments.
--FILE--
<?php

function foo(): void {
    echo "foo()\n";
}

$foo = foo(?);
$foo();

?>
--EXPECT--
foo()
@Crell It could be worth noting that this works fine.
 
10:48 PM
It does.
 
Oh ok, then I missed it.
@Crell I guess noting was the wrong word, mentioning is what I meant.
If that's what you meant, where does it say so?
Oh in Extra Trailing Placeholders I guess.
 
That section, and "use as an identifier".
Really, people keep asking about that feature, and it's talked about a ton, yet people ask about it anyway. :-)
 
At this point I'm just trying to make it crash :P
<?php

function foo($bar) {
    var_dump($bar);
}

$foo = foo(?, bar: ?);
$foo('bar', 'bar2');
@JoeWatkins @Crell Do you agree that this one should fail? Right now it prints 'bar'. For vanilla named params it fails. 3v4l.org/JmVMf
This one also seems wrong. 3v4l.org/5nGdZ (you can see the result under branches).
 
11:06 PM
@IluTov What's wrong with that one?
 
@Crell I would expect the result of both to be the same.
 
I think that's an artifact of named arguments, not partials.
Oh, wait, no, I misread it.
 
That seems correct
The splat operator also splats argument names.
 
@Trowski That's fine. The problem is that the key of the vanilla named argument has a different key than the partial when printing func_get_args().
 
11:11 PM
you didn't use named arguments at call time
 
@JoeWatkins Hm, ok. I find it somewhat counter intuitive that the outer call determines the named argument, and not the partial. I imagined these three being equivalent.
// 1. Vanilla named params
foo(bar: 'bar');

// 2. Closure equivalent
$foo = function ($bar) {
    foo(bar: $bar);
};
$foo('bar');

// 3. Partial equivalent
$foo = foo(bar: ?);
$foo('bar');
I might be wrong.
I'm probably wrong.
 
there's no outer call, there is one call site
 
@JoeWatkins I guess this is where my confusion stems from: If you can't reposition named params and the param name is taken from call site, why support named params in the first place? 3v4l.org/nRoE6
In other words, just appending ? to the function call would do the job to support any named parameter.
 
parameter names are always taken from the call site, you are misidentifying the call site in 2, and possibly 3 ...
I don't know what you mean by reposition params (it has one param) ...
you can give named params out of order during application, or invocation, I don't see the problem ...
the thing we're allowing, because it seems useful for named params is overwriting a named parameter ... that's definitely a deviation and nikita brought it up in review ... it seems useful (and expected/normal) to me ...
sorry, overwriting a position placeholder with a named argument at call time, to be precise ...
anyway, the world is turning fuzzy, I'm going to bed ...
@Crell I'll sort the failing tests tomorrow
 
11:32 PM
g'nite Joe,
 
Sounds good. Should I wait until then to give the list an update?
 
@JoeWatkins It's not a problem per-se. I don't see any value of foo: ? right now because named params in the closure (not call site) only seem useful for reordering params which is not supported in this RFC. Maybe I'm missing something. My brain is tired, I'll see if it makes sense tomorrow :)
Good night!
 
@Crell yeah let's have some thinking time, see how all this looks in the morning ...
nn all
 

« first day (3861 days earlier)      last day (1077 days later) »