-
Notifications
You must be signed in to change notification settings - Fork 7.9k
make FILE_ constants not collide with LOCK_ #11254
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
base: master
Are you sure you want to change the base?
Conversation
Ultimately i wish to make LOCK_SH usable in file_get_contents. With baby steps, i think the first step is to make sure FILE_USE_INCLUDE_PATH does not collide with LOCK_SH (which, prior to this patch, it does) it's annoying to have to write ``` $fp = fopen("file","rb"); flock($fp, LOCK_SH); $content = stream_get_contents($fp); flock($fp, LOCK_UN); fclose($fp); ``` when all i want to write is $content = file_get_contents("file", LOCK_SH); also it's really weird that file_put_contents support LOCK_EX but file_get_contents does not support LOCK_SH.
The userland lock constants are different than the C-land constants.
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.
This test is wild. Let's totally just iterate over a range of ints as flag values and test the behavior 🤦🏻
But, that's not your fault. "Looks good to me."
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.
hehe yeah, and thanks for checking! btw the old check was actually flawed and would miss some incorrect flags, for example flags = 10
aka flags= (1 << 1) | (1 << 3)
is, and always was, incorrect for file() because file() doesn't support PHP_FILE_APPEND, but the old $flags error-check code would miss it. the new check doesn't. As an added bonus, seems the new flags check is about 7% faster too: https://quick-bench.com/q/j3k_unXcE91gVdTRH9Dm0nxpDUA
(probably because it doesn't do the flags < 0
check)
So I'm not to sure if file constants value redefinition is a good idea in general as you could see in one of the tests, some people might actually use the actual int value. This can be even saved in database or some serialized data so it becomes very hard to catch such break. I'm not saying that this is something we can't break but I think there should be a really good reason to do so which I currently don't see here. It would be great if you could propose the API changes to |
@bukka for people using documented arguments, i'm planning 0 BC break: 3 arguments are documented to be valid for file_get_contents()'s 2nd argument: bool(false), bool(true), and FILE_USE_INCLUDE_PATH, and I'm planning to propose changing the argument to ofc, that leaves the edge-cases of people using non-documented arguments, like forget file_get_contents for a second, imagine having to write:
when all you want to write is:
or imagine having to write:
when all you want to write is:
there's several places that would benefit from LOCK_ and FILE_ being compatible.
They're not interested: I tried brining this up 13 months ago (2022-04-23): https://marc.info/?l=php-internals&r=1&w=2&b=202204 - nobody wanted to discuss it. I also tried brining it up 10 days ago (2023-06-06), still nobody wants to discuss it: https://marc.info/?l=php-internals&m=168604887630519&w=2 |
Honestly I really don't like this conversion magic. Personally I don't like anything I don't really understand why all of this cannot be implemented using extra parameter and why we would need flags here? It should not be an issue if it's the last parameter as it can easily be called by name (using named params). I would actually argue that Also note that the flags like In terms of mailing list, it is quite usual to not get any reactions for technical topics and one really need to look to the details of the implementation to see the impact. This particular change has got my objection so it is not going to be merged without RFC in the current form. So to move forward you can choose between those two options:
|
Ultimately i wish to make LOCK_SH usable in file_get_contents. With baby steps, i think the first step is to make sure FILE_USE_INCLUDE_PATH does not collide with LOCK_SH (which, prior to this patch, it does)
it's annoying to have to write
when all i want to write is
$content = file_get_contents("file", LOCK_SH);
also it's really weird that file_put_contents support LOCK_EX but file_get_contents does not support LOCK_SH.