Re: [PHP-DEV] RFC: Strict comparisons

2016-09-24 Thread Rowan Collins
On 23 September 2016 23:14:37 BST, Dan Ackroyd wrote: >On 23 September 2016 at 17:40, Rowan Collins >wrote: >> >> I've been pondering an idea for ages of a generalised syntax for >switch to >> specify an operator to use, so you'd do something like this: > >That's technically possible already: > >

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-23 Thread Dan Ackroyd
On 23 September 2016 at 17:40, Rowan Collins wrote: > > I've been pondering an idea for ages of a generalised syntax for switch to > specify an operator to use, so you'd do something like this: That's technically possible already: function foobar($foo) { switch (true) { case $foo ===

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-23 Thread Rowan Collins
On 23/09/2016 16:59, Stephen Reay wrote: I would however love a way to have strict comparisons in a switch statement. I've been pondering an idea for ages of a generalised syntax for switch to specify an operator to use, so you'd do something like this: switch ( $foo ) use ( === ) { case

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-23 Thread Stephen Reay
I find the idea of making ‘==‘ which has always been a loose comparison, have a new optional way to be ‘more strict’ than ‘===‘ to be quite odd. I would however love a way to have strict comparisons in a switch statement. Cheers Stephen > On 23 Sep 2016, at 20:51, Christian Schneider wrote

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-23 Thread Christian Schneider
Am 19.09.2016 um 15:04 schrieb Vesa Kaihlavirta : > > $two = "2"; > if ($two > 1) { >echo "This sorta works without strict_comparisons=1" . PHP_EOL; > } > > ...would throw a TypeError exception after this change. This sounds like a bad idea to me: Changing the language semantics of some

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-22 Thread Dan Ackroyd
> What still worries me personally is ===. What do you think would be the > least incorrect way to handle === > 2) === is not affected by strict_comparisons. I think not changing it is the correct thing to do.but I think it needs more thinking about. Btw, the RFC would need to cover all cases

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-21 Thread Thomas Lamy
Am 21.09.16 um 14:49 schrieb Vesa Kaihlavirta: On Tue, 20 Sep 2016 at 02:20 Dan Ackroyd wrote: Hi Vesa, On 19 September 2016 at 14:04, Vesa Kaihlavirta wrote: My idea is to add a strict_comparisons declaration that you can add at the beginning of a file in the same way as strict_types. P

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-21 Thread Vesa Kaihlavirta
On Tue, 20 Sep 2016 at 02:20 Dan Ackroyd wrote: > Hi Vesa, > > On 19 September 2016 at 14:04, Vesa Kaihlavirta > wrote: > > > > My idea is to add a strict_comparisons declaration that you can add at > the > > beginning of a file in the same way as strict_types. > > > > Please take a look and let

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-20 Thread Rowan Collins
On 19 September 2016 14:04:48 BST, Vesa Kaihlavirta wrote: >My idea is to add a strict_comparisons declaration that you can add at >the >beginning of a file in the same way as strict_types. The effect would >be >that all normal comparisons would make a type check before doing the >actual >comparis

Re: [PHP-DEV] RFC: Strict comparisons

2016-09-19 Thread Dan Ackroyd
Hi Vesa, On 19 September 2016 at 14:04, Vesa Kaihlavirta wrote: > > My idea is to add a strict_comparisons declaration that you can add at the > beginning of a file in the same way as strict_types. > > Please take a look and let me know if this would be worth a more official > RFC. I think it de

[PHP-DEV] RFC: Strict comparisons

2016-09-19 Thread Vesa Kaihlavirta
Hey all, I've been bouncing this idea of fixing all comparison operations in one fell swoop, although with an opt-in declare in the spirit of strict_types. Here's the gist: ==, < and > plus all the comparisons done inside switch statements and arrays are not very safe. === helps some, but does no