Dimitri Vorontzov 0 Posted January 21, 2013 Report Share Posted January 21, 2013 Chapter 11, pg. 301, contains the following text: If you are running PHP 5.1 or greater, you can add the LOCK_EX constant as the third argument to file_put_contents(): file_put_contents($file, $data, LOCK_EX); To use both the LOCK_EX and FILE_APPEND constants, separate them with the binary OR operator (|): file_put_contents($file, $data, FILE_APPEND | LOCK_EX); It doesn’t matter in which order you list the two constants. This is a really interesting solution, and I'm surprised my mind didn't registered it when I was reading that book for the first time. Could someone please explain to my why the use of | operator is possible in this situation? Is this a common use of such operator, allowing to place two arguments where only one is expected? Are there any other situations where | could be used in similar manner? Thank you in advance for your wisdom! Quote Link to post Share on other sites
HartleySan 826 Posted January 21, 2013 Report Share Posted January 21, 2013 The vertical bar is a bitwise operator in PHP meaning, as Larry states, logical OR. Please see the following for details: http://php.net/manual/en/language.operators.bitwise.php The meaning of the vertical bar as logical OR can be extended for use with function arguments as defined by the PHP language. There are other functions that allow for this usage of the vertical bar with its arguments. For example, the socket_recv function: http://jp2.php.net/manual/en/function.socket-recv.php Quote Link to post Share on other sites
Dimitri Vorontzov 0 Posted January 21, 2013 Author Report Share Posted January 21, 2013 Thank you, HartleySan! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.