Hi everyone

The issue was raised that PHPs LOCK_* constants don't match the Unix
LOCK_* constants.

// Unix
#define LOCK_SH 1
#define LOCK_EX 2
#define LOCK_NB 4
#define LOCK_UN 8

// PHP
#define PHP_LOCK_SH 1
#define PHP_LOCK_EX 2
#define PHP_LOCK_UN 3
#define PHP_LOCK_NB 4

Essentially, in PHPs binary representation UN doesn't get its own bit,
but is instead represented as 0b11. I'm guessing the reasoning was
that SH, EX and UN must not be combined, while they can all be
combined with NB. This avoids additional error handling when multiple
of those bits were to be set.

However, this has a downside of making checking of bits harder and
different from how you would do it in other languages.

We could update the PHP constants to match the Unix values of those
constants. Unfortunately, there seems to be a not insignificant number
of usages of flock with hard-coded integer values.


(The regex engine of sourcegraph is flaky, but the majority of results
are correct)

The process of replacing these hard-coded values could be partially
automated with a few caveats.

1. The value must be direct ($flags = 1; flock($file, $flags); would not work)
2. The migration script would assume that flock is a global and not
local function

Overall, I'm not completely sure this change is worth it since flock
flags are just passed and not read.

Let me know what you think.


PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to