Re: in Operator

From: Date: Tue, 20 Jan 2015 19:07:09 +0000
Subject: Re: in Operator
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-80887@lists.php.net to get a copy of this message
Hi! > Agree, but maybe a RFC for "in" operator and a follow up RFC to allow > "in" on "for" context could be a win/win here as long as one feature > doesn't block each other? The problem is "in" is not just "for". The problem is this: when you say "$foo in $bar", is $foo a value or a key? In many languages, $foo would be a value for a list (and a vector) and a key for a map, but in PHP lists, vectors and maps are the same data type, so you can not implement it in the same way as, say, in Python. I.e. in Python: >>> 1 in [1,2,3] True >>> 1 in {1:'a',2:'b',3:'c'} True >>> 1 in {'a':1, 'b':2, 'c':3} False >>> 5 in [5,6,7] True >>> 5 in {0:5,1:6,2:7} False In PHP, even if it'd be possible to implement such semantics (which I'm not sure), it would be very confusing and hard to explain. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#80887) next »