« first day (5048 days earlier)      last day (37 days later) » 

8:09 AM
Why are we still adding things to bcmath? Isn't it just a poor man's GMP?
 
3 hours later…
11:15 AM
@QuolonelQuestions Because bcmath can do decimals
GMP cannot?
Oh. Well learn something new
But BCMaths' "decimals" has an awful stateful interface
I presume by, "can't do decimals" that you just mean it cannot output decimals, but it must still use fractions internally, no?
No, GMP doesn't support that
It's doing integer maths internally?
11:22 AM
Yes
The n-bit number is just split into multiple native integers
 
7 hours later…
6:06 PM
@nielsdos, I am still quite keen to pursue this idea
Can you help me by confirming whether it's actually possible to "activate" a keyword in the specific context of argument passing? I'm guessing it is, since skipparams actually had an implementation. But it had an implementation 10 years ago...
Essentially, default can be used in an expression, but only in the context of argument passing, so you can't use it as a return value from a function or anything else
I don't exactly know how you define that rule in PHP
The lexer is context-sensitive, and the parser is an LALR-type parser IIRC, so I think it's probably even possible to only modify the parser to look for T_DEFAULT when parsing function arguments
6:28 PM
I don't know what all of that means, but if you say it's possible, I guess we'll figure it out :^)
We need to somehow make sure you can't assign default to a variable, even whilst passing arguments
That is f($v = default) cannot be allowed even though f($v ?? default) is
6:54 PM
I'd like your opinion on something I'm working on.

In some rare cases, you might end up with a specific PHP file that requires a different PHP version then the rest of the project. For example, this happened to me a few times with templates files (generating PHP code to be run elsewhere).

The question, in short, is: if you had to mark such files with a top-level PHPDoc block with an annotation for the PHP version, what would it look like?

For example:`/** @php 5.6 Yeah, sadly it's still in use */` (`@php <version> [<reason>]`)
7:12 PM
Stas' commit did not allow expressions of any kind; it was literally just the keyword, default and nothing else
7:32 PM
Are we sure expressions can work?
8:02 PM
I think we will need to create an entirely new grammar that's a restricted subset of the generalised expr, which permits too much
And then allow that new grammar only in argument_list
@QuolonelQuestions I don't think we want that. What Niels was suggesting is that it may be possible to mark default as a keyword in the lexer depending on context. I'm not sure if that's possible, it might be quite hacky and/or unreliable (imagine $foo::$bar->baz(new class { /* arbitrary code */ }, default). Instead, I would just always lex default as a keyword, and let the compiler switch behavior depending on context.
But in all honestly, I really really don't want argument passing even more complicated. :(
Named args added a lot of complexity, and it almost solves the same problem.
Named args actually doesn't solve the problem at all. It's weird that people think that
What if I want to pass the default argument to the first parameter?
@QuolonelQuestions Then you skip that parameter, and name the others. The case not solvable by default args is $arg ?? default, but I find that to be pretty niche.
I cannot do so conditionally without making the entire function call conditional (rather than just the argument)
You can't just "skip" a parameter, though, because there is no expression that evaluates to nothing (needed to adopt the default)
I unironically have this code in my project right now:
>new PipConfig(...array_filter([isset($theme) ? new $theme : null]))
The stupid ...array_filter() construction is just to omit the parameter if it turns out to be null. But what I really want to write is just isset($theme) ? new $theme : default
Is it really such a bad thing?
@QuolonelQuestions No, not from a language standpoint. But Stas' commit looks way too complicated to be worthwhile for me personally.
8:10 PM
I don't know that all the stuff he did is/was needed
@QuolonelQuestions Right, conditional default is not possible. If there's a simpler solution than the previous implementation, it might be ok. Reflection can now fetch default parameter values, so maybe there's a way to implement this in a simple but slower way.
What do you mean?
Hmmm, yes, conditional default. I think that is really what I'm trying to achieve here, and probably what we should call the RFC, if it comes to that
Although we would also just accept plain default, since that is sometimes useful too
@QuolonelQuestions Rather than making argument sending itself more complicated, default might compile to an opcode that fetches the default argument of the current argument, the same way reflection does. Then argument parsing (user and internal) doesn't need to change.
So it would fetch the default before it knows whether or not it would actually need it, because the expression hasn't resolved yet?
No, you should fetch it when encountering the default keyword, logically.
8:18 PM
OK, sorry. I don't know very much about internals
The difference to the approach from Stas is that he modified the sending opcodes themselves.
If I could manage to implement it the way you described (with a new opcode), would you be happy with that?
We already have 12 (!) sending opcodes, hence my hesitation. I forget which one does what every time I use them.
This new opcode would also be a sending opcode or would it be a different class altogether?
@QuolonelQuestions It would fetch the default value of the argument that is currently being sent. I.e. foo('bar', default) could compile to something like INIT "foo", SEND_VAL "bar", T1 = FETCH_DEFAULT_ARG 2 (the current arg pos or name), SEND_VAL T1, CALL.
8:31 PM
So the new opcode would be FETCH_DEFAULT_ARG
But I have to handle that in 12 different places? 🤔
@QuolonelQuestions You don't, the SEND opcodes just accept the value you fetched.
That avoids having to adjust argument passing at all, including internal functions. If you want to learn more about how function calls work, Nikitas blog has a fantastic writeup. npopov.com/2017/04/14/PHP-7-Virtual-machine.html
Will read
So in terms of modifying the parser, it's fine to just add T_DEFAULT to expr, and then do a ton of compile-time checks to reject it in all the contexts we consider it invalid?
(that seems like it would be a lot of places)
Unless the engine can just automatically throw "unexpected T_DEFAULT" when it's not an argument list
@QuolonelQuestions Do you want to reject it, or just handle it as we do currently, i.e. as a constant? But yes, you can either just keep it as a string, and conditionally treat it as a special constant in the compiler if the string matches "default", or you make it a keyword and fall back to the existing constant/function behavior when outside of argument sending. The former is probably easier.
@QuolonelQuestions I never had a use for this myself, but if the patch isn't complex, I won't object.
I thought you didn't write PHP though :^)
@QuolonelQuestions I've written PHP professionally for ~8 years.
8:43 PM
@IluTov You kinda lost me with all that. We currently treat default as a constant??? We do? I thought it was a keyword, and only in the context of switch
And match
@QuolonelQuestions Ahh, I forgot this is already a keyword. Nevermind then.
So, just make it part of expr but reject it when not inside args.
@IluTov Didn't you even write match() xD
@IluTov Is that a fairly easy thing to do? I thought it would have to be checked in a lot of different contexts
@IluTov (Speaking of, my editor shows the double semicolon as an error) i.imgur.com/KVUWdEv.png
(I guess it's harmless though)
@QuolonelQuestions During compilation, you'd need to remember some context, and then when encountering the default AST marker, you can check whether you're inside an arg and handle it accordingly.
8:50 PM
We currently don't know if we're inside an arg? Or does the context tracking have to be added per-opcode?
@QuolonelQuestions This was strictly referring to compile time. I.e. when traversing the AST.
I find it really weird that, without modification, PHP currently gives this error for this code:
`f(default);`
>Parse error: syntax error, unexpected token ")", expecting ":" in /in/ZCDKY on line 4
It's like it thinks we're already in a switch statement???
But that shouldn't be possible
@QuolonelQuestions It thinks it's the name of a named arg.
Oh heh
What's the difference between argument_list and parameter_list?
Oh one is declaring and the other is passing
You pass parameters to arguments huh
I always used those two nouns interchangably
9:41 PM
What exactly is the purpose/meaning of the UNEXPECTED macro?
9:59 PM
Somehow I cannnot add T_DEFAULT to expr and I don't really understand the error :<
> bison.exe -Wall --output=Zend/zend_language_parser.c -v -d Zend/zend_language_parser.y
Zend/zend_language_parser.y: error: shift/reduce conflicts: 3 found, 0 expected
Zend/zend_language_parser.y: error: reduce/reduce conflicts: 1 found, 0 expected
I guess it's somehow an ambiguous grammar?
10:20 PM
Actually it's arguments to parameters, derp
10:58 PM
I worked around it by creating a new expr_with_default type that includes expr | T_DEFAULT and is only used in argument. However, this only permits the bare-word default, i.e. f(default) and not f($x ?? default) because expr does not recurse into expr_with_default and I don't think there's any way I can write it so that it does :<
Also I have no idea how to actually make this new opcode do anything useful lol. I think maybe this is beyond my ability level 😢
It's weird that PHP doesn't crash or anything when it encounters an unknown opcode
Maybe I didn't even emit it properly. I have no idea what I'm doing

« first day (5048 days earlier)      last day (37 days later) »