-
Notifications
You must be signed in to change notification settings - Fork 7.9k
use bit shift to set bitflags #2 #8429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! It's a bit unfortunate that
PHP_LOCK_UN
looks like an option combiningPHP_LOCK_SH
andPHP_LOCK_EX
when it's really just a different option. Maybe this could be made more obvious by keeping these options continuous integers.It's unfortunate that we have a different binary representation here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunate indeed, as it breaks code like https://3v4l.org/0XT2P
(which is perfectly valid code in most other languages, like C)
they shouldn't continuous integers, they should be continuous bits, because they are in fact bitflag options, as they're supposed to be combined with LOCK_SH | LOCK_NB and LOCK_EX | LOCK_NB
(but afaik LOCK_UN is not supposed to be combined with LOCK_NB)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree, they should be. Unfortunately in PHP they are not.
Yeah this is not great. The check
($flags & ~LOCK_NB) === LOCK_SH
would be correct but obviously suboptimal. It might be worth addressing this in internals and potentially fix it in PHP 8.2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah would be nice to get LOCK_UN fixed, but in the meantime i still think this PR should be merged ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No? This is clearly not a bitmask, so you shouldn't try to make it look like one. This is a two bit lock type and an NB flag -- writing the two-bit type as if it were a combination of independent bits doesn't make any sense.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikic btw do you have an opinion on this? https://www.reddit.com/r/programminghorror/comments/uapuo7/php_invented_their_own_nonstandard_value_for_lock/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That programmer should have better read the fine manual: