|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79993 SplFileObject::flock has LOCK_NB as a valid operation
Submitted: 2020-08-18 21:04 UTC Modified: 2020-08-18 23:29 UTC
From: Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2020-08-18 21:04 UTC]
The documentation of SplFileObject::flock specifies that LOCK_NB is a valid operation whereas flock() says that one needs to add this option as a bitmask to the operation argument.

As SplFileObject::flock just calls PHP's normal flock function (or at least attempts to) we need to look at its implementation.

The behaviour of flock is correctly documented as one can see by the following implementation details (on master) [Note: PHP_LOCK_NB = 4] :

	/* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
	act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);

And it warns/throw (on master) if passed on its own as can be seen:

	act = operation & 3;
	if (act < 1 || act > 3) {
		zend_argument_value_error(2, "must be either LOCK_SH, LOCK_EX, or LOCK_UN");


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-18 23:28 UTC]
Automatic comment on behalf of cmb
Log: Fix #79993: SplFileObject::flock has LOCK_NB as a valid operation
 [2020-08-18 23:28 UTC]
-Status: Open +Status: Closed
 [2020-08-18 23:29 UTC]
-Assigned To: +Assigned To: cmb
 [2020-08-19 03:05 UTC]
Automatic comment on behalf of mumumu
Log: Fix #79993: SplFileObject::flock has LOCK_NB as a valid operation
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Nov 24 13:01:23 2020 UTC