[pmwiki-users] bitwise assignment on HandleEdit

DaveG pmwiki at solidgone.com
Fri May 7 21:55:35 CDT 2010



On 5/7/2010 12:32 PM, Carlos AB wrote:
> I've read the php manual about bitwise operators but couldn't
> understand the code below:
>
>    $EnablePost&= preg_grep('/^post/', array_keys(@$_POST));
Interesting question. I had to research, but here's how I'd interpret it.

 From [1]: &= is bitwise 'and':   A &= B is the same as (A = A & B)

1] &= will perform a bitwise AND operation on the result of the the 
preg_grep, and the value of $EnablePost.
2] The preg_grep will return an array of the result of a search of the 
keys of the array $_POST for anything starting with the text 'post'

So, the bitwise operator will scan each element of the array returned by 
$_POST, and do an 'and' with $EnablePost. So:

Initial value of$EnablePost:	0/unset	1	1
'post' found in array:	 	1	1	0
Result: 			0	1	0

So, if $EnablePost is already set, and 'post' is in the $_POST array, 
then keep it set, otherwise disable posting.


  ~ ~ Dave

[1]http://php.comsci.us/etymology/operator/assignment.php
[2]http://php.comsci.us/etymology/operator/bitwiseand.php



More information about the pmwiki-users mailing list