Re: [PHP-DEV] Interruptions

2018-09-26 Thread Marcos Passos
Have you tried generators? It looks like you are trying to implement
coroutines.

You can learn more about cooperative multitasking in PHP on this awesome
post written by Nikic:
https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html

- Marcos

On Wed, Sep 26, 2018 at 16:47 David Rodrigues 
wrote:

> I do not know if I can get the same result with the current PHP features
> without taking many turns. So I thought of a feature that I'm initially
> calling "interruptions" (similar to those that occur on a CPU).
>
> Nowadays we have the Exceptions, which stop the execution of a function and
> initiate a process of "catch" and treatment of the same. So I thought of
> something similar, but did not break the execution flow, allowing reactions
> to depend on what was happening inside a function.
>
> It would basically work according to the following flow (the square
> brackets number is the execution order):
>
> function sum(int $a, int $b): int {
> [2] interrupts with new SumInterruption($a, $b);
> [5] return $a + $b;
> }
>
> interruptable {
>   [6] $sum = [1] sum(1, 2);
>   [7] printf($sum);
> }
> [3] catch (SumInterruption $interruption) {
>   [4] printf('Calculating: %d + %d = ', $interruption->a,
> $interruption->b);
> }
>
> Using current PHP features I can do like that:
> https://pastebin.com/Bci6BBfi
>
> Note that all code will be executed, and the interpection will only
> redirect temporarily the execution flow to the "catch" block, then will
> back to "sum()" block to return the sum. Like Exceptions, an Interruption
> will traverse the code execution tree until find a interruption catch
> block, but if it doesn't exists, just not will happen (or maybe throw
> InterruptionNotHandledException or something like it).
>
> In one of my real example cases, I have a code that could be manipulated by
> another method. Currently I need argument the self instance to this method,
> so it could run another method from the caller method to make some
> adjustments, which is a bit confuses.
>
> I hope you understand my point, and I am open to discuss that.
>
> Thanks!
>
> --
> David Rodrigues
>


[PHP-DEV] Interruptions

2018-09-26 Thread David Rodrigues
I do not know if I can get the same result with the current PHP features
without taking many turns. So I thought of a feature that I'm initially
calling "interruptions" (similar to those that occur on a CPU).

Nowadays we have the Exceptions, which stop the execution of a function and
initiate a process of "catch" and treatment of the same. So I thought of
something similar, but did not break the execution flow, allowing reactions
to depend on what was happening inside a function.

It would basically work according to the following flow (the square
brackets number is the execution order):

function sum(int $a, int $b): int {
[2] interrupts with new SumInterruption($a, $b);
[5] return $a + $b;
}

interruptable {
  [6] $sum = [1] sum(1, 2);
  [7] printf($sum);
}
[3] catch (SumInterruption $interruption) {
  [4] printf('Calculating: %d + %d = ', $interruption->a, $interruption->b);
}

Using current PHP features I can do like that: https://pastebin.com/Bci6BBfi

Note that all code will be executed, and the interpection will only
redirect temporarily the execution flow to the "catch" block, then will
back to "sum()" block to return the sum. Like Exceptions, an Interruption
will traverse the code execution tree until find a interruption catch
block, but if it doesn't exists, just not will happen (or maybe throw
InterruptionNotHandledException or something like it).

In one of my real example cases, I have a code that could be manipulated by
another method. Currently I need argument the self instance to this method,
so it could run another method from the caller method to make some
adjustments, which is a bit confuses.

I hope you understand my point, and I am open to discuss that.

Thanks!

-- 
David Rodrigues


Re: [PHP-DEV] Re: Pre proposal for "Class extension functions"

2018-09-26 Thread Rasmus Schultz
On Mon, Sep 24, 2018 at 11:24 PM Andrew Gromov  wrote:

> > Bring a little Javascript into PHP?
>
> In fact, I looked at Kotlin :)

Kotlin does not modify classes.

This sort of thing is sound in compiled languages like Kotlin and C#, where
this is really syntactic sugar for calling user-defined functions with
object-like
syntax - it's possible (and sound) *only* because these languages can resolve
such calls at compile-time.

In dynamic languages like JavaScript, you're literally writing to a
map of methods,
which means execution order is critical, and overwrites are possible - just two
reasons why this feature isn't sound in languages like JavaScript, and wouldn't
be in PHP either.

What's wrong with just calling a function and passing the object as argument?

In my opinion, this is the kind of pointless feature that brings nothing new and
invites inconsistent code and bikeshedding over pointless details.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Pre proposal for "Class extension functions"

2018-09-26 Thread Sebastian Bergmann
On 9/25/18 10:48 PM, Sara Golemon wrote:
> I've been back-burnering this for a few days and I'm with Stas.  I
> don't like this proposal because it adds complexity with relatively
> little benefit.

I only see problems (mostly due to added complexity) and no benefits. -1
from me.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Re: [RFC] [VOTE] Typed properties v2

2018-09-26 Thread Mathieu Girard
 This is a great news !

At AFUP (French Php User Group) we all wanted to +1.

Thanks for your work on this

Le mer. 26 sept. 2018 à 15:46, Nikita Popov  a écrit :

> On Tue, Sep 11, 2018 at 9:05 AM Bob Weinand  wrote:
>
> > Hey,
> >
> > As announced, we are starting the vote on typed properties today.
> >
> > The voting period is two weeks, until sometime in the evening on Tuesday
> > 25-09-2018.
> >
> > Please find the RFC at https://wiki.php.net/rfc/typed_properties_v2.
> >
> > Bob and Nikita
>
>
> I'm pleased to announce that the typed properties RFC has been accepted
> with 70 votes in favor and one vote against. We will work to finalize and
> merge the implementation in the next few days.
>
> Regards,
> Bob and Nikita
>


-- 
Mathieu GIRARD, AFUP - French UG
http://php-internals.afup.org/


Re: [PHP-DEV] Re: [RFC] [VOTE] Typed properties v2

2018-09-26 Thread Ivan Enderlin

On 26.09.18 15:46, Nikita Popov wrote:

On Tue, Sep 11, 2018 at 9:05 AM Bob Weinand  wrote:


Hey,

As announced, we are starting the vote on typed properties today.

The voting period is two weeks, until sometime in the evening on Tuesday
25-09-2018.

Please find the RFC at https://wiki.php.net/rfc/typed_properties_v2.

Bob and Nikita


I'm pleased to announce that the typed properties RFC has been accepted
with 70 votes in favor and one vote against. We will work to finalize and
merge the implementation in the next few days.

\o/

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Re: [RFC] [VOTE] Typed properties v2

2018-09-26 Thread Nikita Popov
On Tue, Sep 11, 2018 at 9:05 AM Bob Weinand  wrote:

> Hey,
>
> As announced, we are starting the vote on typed properties today.
>
> The voting period is two weeks, until sometime in the evening on Tuesday
> 25-09-2018.
>
> Please find the RFC at https://wiki.php.net/rfc/typed_properties_v2.
>
> Bob and Nikita


I'm pleased to announce that the typed properties RFC has been accepted
with 70 votes in favor and one vote against. We will work to finalize and
merge the implementation in the next few days.

Regards,
Bob and Nikita