-
Notifications
You must be signed in to change notification settings - Fork 6
Check existing parameter naming for consistency, clarity and possible brevity #16
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
Comments
See also https://gist.github.com/nikic/b1223525b8bb0a1bef0f6b8a267318e9 for a list of currently used parameter names, as of a week ago. |
Question: DOMDocument uses $filname a lot, the whole API is mostly camel case, so question would be $fileName or $filename? Edit: Mark made a good suggestion to rename these in dom explicitly to $path |
On 25 July 2020 20:55:50 BST, Benjamin Eberlei ***@***.***> wrote:
Question: DOMDocument uses $filname a lot, the whole API is mostly
camel case, so question would be $fileName or $filename?
$filename
Making this $fileName, although arguably more "correct" is also obnoxious. Just like $tineZone would be.
|
I've given ext/date another pass. Should be done now. In general, I'm not a fan of short names like |
@derickr For the specific instance of |
FWIW I like most of the suggestions in the OP, except for However, Nikita also expressed that he'd prefer abbreviations where it's possible, so I think we should come up with some heuristics when to consider to use them:
While Even if we agreed to use the above rule of thumbs, we'd be using abbreviations pretty much inconsistently, because parameter names would be mostly non-abbreviated, with some "random" exceptions. In order to fix this inconsistency, we could have another heuristics:
For example, it's not likely that someone writes |
https://gist.github.com/TysonAndre/8d71559febf58f6af41cce009d4fc704#file-gistfile1-txt-L15 has some notes on the differences between php-src and Phan, which uses function signatures from a variety of places
There's a collection of scripts I wrote in https://github.com/phan/phan/tree/master/internal (internalsignatures.php and lib/) which were originally designed for extracting union types, but can be adapted for extracting parameter names. They're not exactly designed for reuse, but it's still doable (extract all from stubs file, extract all from svn, and compare where they differ in naming).
This also found some bugs.
zend_long x1, y1, x2, y2;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &im_zval, gd_image_ce, &x1, &y1, &x2, &y2) == FAILURE) {
RETURN_THROWS();
}
|
Oh, this is a fun thread. Related: php/php-src#6027 In chat, Levi suggested standardizing array functions on "input" and "callback" (where it's currently a combination of array, array1, or various less sensible things). That seems sensible to me if it does to everyone else. |
Another related PR: php/php-src#6032 |
$input seems reasonable - it'd hopefully make it easier to remember the names if it was used everywhere where there was one input array. It also works better when there's also collection support, or for
Maybe we should focus on adding positional-only parameters to php 8.0 to avoid this if we can't decide (I'm kidding) -- I doubt the release managers would give that an extension, and that addition may break extensions such as debuggers until they implemented support |
For most of the array functions, they take only an array and don't modify it, so $input seems reasonable to me. (I also considered $source, but I like $input better.) For the moment I'm not dealing with iterables; I don't expect array_map() to ever start taking an iterable, honestly. For mutating functions like sort() et al, $array is probably the best option. Anything else gets kind of abstract, like $subject. Absent any better ideas I'm good leaving those as is. |
I prefer $array over $input. "Input" is very generic and could refer to literally any parameter. |
After some consideration, I feel the same way There's also the inconsistency of having generic object functions accept $object, some generic string functions accept $str/$string, feof accepting handle/resource, but array functions expecting $input. It'd be easier to see wrongness visually with |
I've put together a script to compare the stubs used by php-src 8.0 with the parameter names in php.net https://gist.github.com/TysonAndre/1994cc681ad04109b7ab3f2fd7407b6f There's around 800 mismatches. Some notable differences:
|
New PR that covers all of array functions: php/php-src#6046 Docs to be updated accordingly after that gets merged. |
I was just wondering what to do with extensions that expose a dual object oriented / procedural API. For these extensions the class methods have equivalent global functions. We use different parameter naming styles for functions and methods. However, it seems like the dual APIs share the signatures between a method and its equivalent function. That means we presently cannot use different parameter naming styles for the two APIs without changing something about the method/function mapping mechanism. Solving this requires changes to the stub parser, right? |
@dtakken I think there's no technical issue with using different parameter names in aliases. When I was making changes to this file today (I assume you saw it? :) ) I was close to rename the parameters in question to use the correct case, but I wanted to have some discussion first, so changed my mind. |
@kocsismate Ok then I do not understand how it works. :) I only see it generate one function signature in the *_arginfo.h file. I do see that an Yes, I saw your changes. Great job. |
The alias in the context of stubs only means that the same C code ( |
@kocsismate Ah yes, I see it now. I was looking into it to see how I might help a bit with this effort. Now I know. Thanks! |
This PR was merged into the 1.19-dev branch. Discussion ---------- Fix the name of arguments for PHP 8 With PHP 8 coming, we need to have function/methods parameters names consistent between polyfills and the original implementations. I'm not sure if this is all of it yet. see: php/php-tasks#23 php/php-tasks#16 Commits ------- f75e14e Fix the name of arguments for PHP 8
With PHP 8 released, I think it's safe to close this... |
General issue to track naming suggestions:
Let me start with string functions...
General name conventions:
is_something: true
in a named function call does not help oversomething: true
The text was updated successfully, but these errors were encountered: