Re: [RFC] [DISCUSSION] Type casting in array destructuring expressions

From: Date: Tue, 07 Apr 2020 15:58:36 +0000
Subject: Re: [RFC] [DISCUSSION] Type casting in array destructuring expressions
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-109556@lists.php.net to get a copy of this message
> > I also like Levi's proposal but for the use cases which lead me to the > idea for this proposal where I explicitly want to cast values and don't > check their current types it's difficult to use. I think it serves > different use cases. > My personal pov is that the use case you describe is not sound enough to require a new syntax; this is still fine and explicit (borrowing from one of your examples), especially considering the weak points noted by Rowan: $now = (int) $a[0]; $future = (int) $a[1]; The huge benefit of Levi's proposal is that it works with any types, not just the castable ones: any class/interface would fit there. This means this new syntax would provide another "type barrier" that could help the engine or any type analyzer get a better understanding of the variables at hand. > You mention the syntax looks weird to you. How would you design the > syntax if you want to cast the values instead of type checking them? > I would abstain from trying to answer then. I now understand you had this different use case in mind, so I would totally understand that in turn, you'd be not interested in working towards Levi's proposal. On the other hand, I would so much like you'd be :) Cheers, Nicolas

« previous php.internals (#109556) next »