Hi all,
First of all, I have no intention to remove nor deprecate old function
names.
Old function names must exist for compatibility and should be able to use
forever.
We have CODING_STANDARDS[1] for a long time.
However, PHP has so many functions that do not confirm this. Many of
violating functions can have standard conforming names safely
This RFC[2] proposes the CODING_STANDARDS confirmed function names.
The list[3] is almost complete, but improvement can be added. For example,
get_rusage() could be sys_get_rusage() because there is sys_getloadavg()
already.
There would not be much opinions for independent modules like BCMath, GD.
Please take a look for others and give your comments.
Thank you!
[1] https://github.com/php/php-src/blob/master/CODING_STANDARDS
[2] https://wiki.php.net/rfc/consistent_function_names
[3]
https://wiki.php.net/rfc/consistent_function_names#list_of_functions_to_be_renamed
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi,
I think the new functions must have consistent parameters order too. I
think it is about the right time, so we'll have a cleaner and more logical
language.
ATM, it's a real headache, we constantly have to read the documentation to
make sure we give the arguments in the right order.
For instance
-
implode()
: "implode() can, for historical reasons, accept its
parameters in either order. " - strpos( $haystack, $needle )
- in_array( $needle, $haystack )
Regards.
Le Mon, 02 Mar 2015 22:52:03 +0100, Yasuo Ohgaki yohgaki@ohgaki.net a
écrit:
Hi all,
First of all, I have no intention to remove nor deprecate old function
names.
Old function names must exist for compatibility and should be able to use
forever.We have CODING_STANDARDS[1] for a long time.
However, PHP has so many functions that do not confirm this. Many of
violating functions can have standard conforming names safelyThis RFC[2] proposes the CODING_STANDARDS confirmed function names.
The list[3] is almost complete, but improvement can be added. For
example,
get_rusage() could be sys_get_rusage() because there issys_getloadavg()
already.There would not be much opinions for independent modules like BCMath, GD.
Please take a look for others and give your comments.Thank you!
[1] https://github.com/php/php-src/blob/master/CODING_STANDARDS
[2] https://wiki.php.net/rfc/consistent_function_names
[3]
https://wiki.php.net/rfc/consistent_function_names#list_of_functions_to_be_renamed--
Yasuo Ohgaki
yohgaki@ohgaki.net
--
Utilisant le logiciel de courrier d'Opera : http://www.opera.com/mail/
Hi Benoit,
On Wed, Mar 4, 2015 at 2:34 AM, Benoit Schildknecht bensor987@neuf.fr
wrote:
I think the new functions must have consistent parameters order too. I
think it is about the right time, so we'll have a cleaner and more logical
language.ATM, it's a real headache, we constantly have to read the documentation to
make sure we give the arguments in the right order.For instance
implode()
: "implode() can, for historical reasons, accept its
parameters in either order. "- strpos( $haystack, $needle )
- in_array( $needle, $haystack )
$needle should be 2nd argument like
int strpos ( string $haystack , mixed $needle [, int $offset= 0 ] )
string stristr ( string $haystack , mixed $needle [, bool $before_needle =
false ] )
Rasmus suggested to have IEEE 1003.1 compliance. I like the idea and I'll
add
this in the RFC, probably. These are the order of parameters.
So array functions are subject to be changed.
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_in() and fix order.
mixed array_search ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_find() and fix order.
bool array_key_exists ( mixed $key , array $array )
Renamed to array_key_find() and fix order.
array array_keys ( array $array [, mixed $search_value [, bool $strict =
false ]] )
OK as it is now.
implode()
may be changed to have
string implode ( string $glue , array $pieces )
always.
If there are missing functions, please let me know.
I'll try to address.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
If we introduce those new aliases, it should be clearly stated in the docs
which function should be used, maybe we can remove the old one in the far
future then. But the more important point is, that it's not that confusing
to users. Which one should I use? Why's there another one? We already have
that situation with count
and sizeof
.
Regards, Niklas
2015-03-05 9:07 GMT+01:00 Yasuo Ohgaki yohgaki@ohgaki.net:
Hi Benoit,
On Wed, Mar 4, 2015 at 2:34 AM, Benoit Schildknecht bensor987@neuf.fr
wrote:I think the new functions must have consistent parameters order too. I
think it is about the right time, so we'll have a cleaner and more
logical
language.ATM, it's a real headache, we constantly have to read the documentation
to
make sure we give the arguments in the right order.For instance
implode()
: "implode() can, for historical reasons, accept its
parameters in either order. "- strpos( $haystack, $needle )
- in_array( $needle, $haystack )
$needle should be 2nd argument like
int strpos ( string $haystack , mixed $needle [, int $offset= 0 ] )
string stristr ( string $haystack , mixed $needle [, bool $before_needle =
false ] )Rasmus suggested to have IEEE 1003.1 compliance. I like the idea and I'll
add
this in the RFC, probably. These are the order of parameters.So array functions are subject to be changed.
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_in() and fix order.mixed array_search ( mixed $needle , array $haystack [, bool $strict ]
)
Renamed to array_find() and fix order.bool array_key_exists ( mixed $key , array $array )
Renamed to array_key_find() and fix order.array array_keys ( array $array [, mixed $search_value [, bool $strict =
false ]] )
OK as it is now.
implode()
may be changed to have
string implode ( string $glue , array $pieces )
always.If there are missing functions, please let me know.
I'll try to address.Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Niklas,
If we introduce those new aliases, it should be clearly stated in the docs
which function should be used, maybe we can remove the old one in the far
future then. But the more important point is, that it's not that confusing
to users. Which one should I use? Why's there another one? We already have
that situation withcount
andsizeof
.
Good point!
I'll update documents so that main function is prefered name/function to be
used.
Functions that have different parameter order may be marked as to be
deprecated.
Other aliases may be used. I'll add this in the RFC.
Thank you for the feedback.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Niklas,
If we introduce those new aliases, it should be clearly stated in the
docs
which function should be used, maybe we can remove the old one in the
far
future then. But the more important point is, that it's not that
confusing
to users. Which one should I use? Why's there another one? We already
have
that situation withcount
andsizeof
.Good point!
I'll update documents so that main function is prefered name/function
to be
used.
This would be fine if all the users read the manual, and only the manual. What about the thousands of books, tutorials, blog posts, Stack Overflow q&as, etc, all mentioning the names and behaviour that have been around for 15 to 20 years? Not to mention the thousands of lines of existing code which people will not only need to read and understand, but also contribute to without accidentally breaking compatibility with old versions of PHP.
Regards,
Rowan Collins
[IMSoP]
Good point!
I'll update documents so that main function is prefered name/function
to be
used.
This would be fine if all the users read the manual, and only the manual. What about the thousands of books, tutorials, blog posts, Stack Overflow q&as, etc, all mentioning the names and behaviour that have been around for 15 to 20 years? Not to mention the thousands of lines of existing code which people will not only need to read and understand, but also contribute to without accidentally breaking compatibility with old versions of PHP.
This is perhaps the key ...
Yasuo has at least now come on board over the IEEE standards but has
also spotted that because of allowing a little to much freedom in the
past some of the current guide lines do not marry with the well
established standards :(
The bit I'm still unsure of here is not so much messing with some of the
fine detail of the procedural based functions, but the coding standard
that ACTUALLY applies at the object level. Using one naming standard for
ths area and a different one for an object version of the same set of
functions is equally confusing?
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
Hi Lester,
Good point!
I'll update documents so that main function is prefered name/function
to be
used.
This would be fine if all the users read the manual, and only the
manual. What about the thousands of books, tutorials, blog posts, Stack
Overflow q&as, etc, all mentioning the names and behaviour that have been
around for 15 to 20 years? Not to mention the thousands of lines of
existing code which people will not only need to read and understand, but
also contribute to without accidentally breaking compatibility with old
versions of PHP.This is perhaps the key ...
Yasuo has at least now come on board over the IEEE standards but has
also spotted that because of allowing a little to much freedom in the
past some of the current guide lines do not marry with the well
established standards :(
I've updated the RFC to have IEEE names as well as other established
library function
names as valid names. We wouldn't have much problem having aliases for it.
I think
it would be useful.
The bit I'm still unsure of here is not so much messing with some of the
fine detail of the procedural based functions, but the coding standard
that ACTUALLY applies at the object level. Using one naming standard for
ths area and a different one for an object version of the same set of
functions is equally confusing?
I agree. I wouldn't rush into.
If we change, we should change them right.
We have the implementation already.
http://php.net/arrayobject
I looked into the implementation. I'm surprised that it's overly
complicated.
It uses "array(hash)" and "object" for array storage for some reasons. This
makes it difficult to reuse procedural implementation. We may do something
for this issue.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Lester,
Good point!
I'll update documents so that main function is prefered name/function
to be
used.
This would be fine if all the users read the manual, and only the
manual. What about the thousands of books, tutorials, blog posts, Stack
Overflow q&as, etc, all mentioning the names and behaviour that have been
around for 15 to 20 years? Not to mention the thousands of lines of
existing code which people will not only need to read and understand, but
also contribute to without accidentally breaking compatibility with old
versions of PHP.
This is perhaps the key ...Yasuo has at least now come on board over the IEEE standards but has
also spotted that because of allowing a little to much freedom in the
past some of the current guide lines do not marry with the well
established standards :(
I've updated the RFC to have IEEE names as well as other established
library function
names as valid names. We wouldn't have much problem having aliases for it.
I think it would be useful.
One of my own personal gripes has always been that while some names are
consistent with the standard, the rules for adding names adopted at the
time wasn't? It is this which has created the problem and if there is
any reason to change things now it should be to follow the IEEE coding
style which is also followed by secondary libraries like gettext.
is_int should simply be isint in line with the IEEE standard but that
divergence of standards was not a good enough reason to avoid the
current 'inconsistencies' at the time?
The bit I'm still unsure of here is not so much messing with some of the
fine detail of the procedural based functions, but the coding standard
that ACTUALLY applies at the object level. Using one naming standard for
ths area and a different one for an object version of the same set of
functions is equally confusing?I agree. I wouldn't rush into.
If we change, we should change them right.We have the implementation already.
http://php.net/arrayobjectI looked into the implementation. I'm surprised that it's overly
complicated.
It uses "array(hash)" and "object" for array storage for some reasons. This
makes it difficult to reuse procedural implementation. We may do something
for this issue.
One of the reasons I don't think it as caught on?
But the starting point here is naming methods in these objects and the
'assumed standard' seems to be camelCaseStyle rather than under_style ?
Again the horse has bolted since objects like http are now well
established with camelCaseStyle rather than following the C coding style
anyway.
The only question that needs answering first is just what standard ARE
we working to and what should that be to be consistent between
procedural and object models?
--
Lester Caine - G8HFL
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk
Hi all,
Hi Lester,
Good point!
I'll update documents so that main function is prefered name/function
to be
used.
This would be fine if all the users read the manual, and only the
manual. What about the thousands of books, tutorials, blog posts, Stack
Overflow q&as, etc, all mentioning the names and behaviour that have
been
around for 15 to 20 years? Not to mention the thousands of lines of
existing code which people will not only need to read and understand,
but
also contribute to without accidentally breaking compatibility with old
versions of PHP.
This is perhaps the key ...Yasuo has at least now come on board over the IEEE standards but has
also spotted that because of allowing a little to much freedom in the
past some of the current guide lines do not marry with the well
established standards :(
I've updated the RFC to have IEEE names as well as other established
library function
names as valid names. We wouldn't have much problem having aliases for
it.
I think it would be useful.One of my own personal gripes has always been that while some names are
consistent with the standard, the rules for adding names adopted at the
time wasn't? It is this which has created the problem and if there is
any reason to change things now it should be to follow the IEEE coding
style which is also followed by secondary libraries like gettext.is_int should simply be isint in line with the IEEE standard but that
divergence of standards was not a good enough reason to avoid the
current 'inconsistencies' at the time?
I don't know how CONDING_STARNDARDS is made. Anyone remember
the discussion?
PHP has function names copied from C libraries at the beginning. Then
name with "_" became standard. Therefore, we have phpversion()
, isset().
I remember empty() discussion whether it should be is_empty() or empty().
Shorter name is preferred and empty() is used. We chose
inconsistent names on occasions like StdClass::__set_state().
Having C library like name is not bad, but I think too many aliases are
better
to be avoided. Especially for basic functions. I'm not sure if it's good
for PHP
to have isstring(), isarray(), etc. It's one possibility though.
The bit I'm still unsure of here is not so much messing with some of the
fine detail of the procedural based functions, but the coding standard
that ACTUALLY applies at the object level. Using one naming standard for
ths area and a different one for an object version of the same set of
functions is equally confusing?I agree. I wouldn't rush into.
If we change, we should change them right.We have the implementation already.
http://php.net/arrayobjectI looked into the implementation. I'm surprised that it's overly
complicated.
It uses "array(hash)" and "object" for array storage for some reasons.
This
makes it difficult to reuse procedural implementation. We may do
something
for this issue.One of the reasons I don't think it as caught on?
But the starting point here is naming methods in these objects and the
'assumed standard' seems to be camelCaseStyle rather than under_style ?
Again the horse has bolted since objects like http are now well
established with camelCaseStyle rather than following the C coding style
anyway.The only question that needs answering first is just what standard ARE
we working to and what should that be to be consistent between
procedural and object models?
Function names without "" is better for camelCase methods. I agree.
Personally, I don't have any bad impression for having "" for procedural
functions while having camelCase for methods.
It's valid option to have camelCase for procedural functions' main name.
I don't mind removing "" from procedural functions much, but C library
names are not standardized well enough. (I mean naming convention
differs library to library) My current impression is having "" in names
and have PHP name would seem more consistent.
I guess this is the reason why CODING_STANDARDS is made like it
is now. We may introduce new procedural naming standard with
camelCase name that can keep consistency.
Thoughts?
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
So array functions are subject to be changed.
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_in() and fix order.mixed array_search ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_find() and fix order.bool array_key_exists ( mixed $key , array $array )
Renamed to array_key_find() and fix order.array array_keys ( array $array [, mixed $search_value [, bool $strict =
false ]] )
OK as it is now.
implode()
may be changed to have
string implode ( string $glue , array $pieces )
always.
If we do create new array functions I think it should be thought through
a bit more than just cleaning up the arg order. For example we could
support Traversable as well. Then at least it'd bring some value beyond
consistency for the sake of it.
Cheers
Hi Jordi,
So array functions are subject to be changed.
bool in_array ( mixed $needle , array $haystack [, bool $strict ] )
Renamed to array_in() and fix order.mixed array_search ( mixed $needle , array $haystack [, bool $strict
] )
Renamed to array_find() and fix order.bool array_key_exists ( mixed $key , array $array )
Renamed to array_key_find() and fix order.array array_keys ( array $array [, mixed $search_value [, bool $strict =
false ]] )
OK as it is now.
implode()
may be changed to have
string implode ( string $glue , array $pieces )
always.If we do create new array functions I think it should be thought through a
bit more than just cleaning up the arg order. For example we could support
Traversable as well. Then at least it'd bring some value beyond consistency
for the sake of it.
I agree. Do you have more detailed suggestion for this?
http://ruby-doc.org/core-2.2.0/Array.html
https://docs.python.org/3/tutorial/datastructures.html
https://docs.python.org/2/library/array.html
https://scipy-lectures.github.io/intro/numpy/array_object.html
We have a lot of array_u*() functions such as
http://php.net/manual/en/function.array-uintersect-uassoc.php
array array_uintersect_uassoc ( array $array1 , array $array2 [, array $...
], callable $value_compare_func , callable $key_compare_func )
this can be consolidated to
http://php.net/manual/en/function.array-intersect-assoc.php
array array_intersect_assoc ( array $array1 , array $array2 [, array $... ]
)
All of these has callback the end of parameters. These may be consolidated.
I'll add this to the RFC if this is preferred.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
We have a lot of array_u*() functions such as
http://php.net/manual/en/function.array-uintersect-uassoc.php
array array_uintersect_uassoc ( array $array1 , array $array2 [, array $...
], callable $value_compare_func , callable $key_compare_func )
this can be consolidated to
http://php.net/manual/en/function.array-intersect-assoc.php
array array_intersect_assoc ( array $array1 , array $array2 [, array $... ]
)All of these has callback the end of parameters. These may be consolidated.
I'll add this to the RFC if this is preferred.
Those functions both take any number of arguments, so given a function
call with 4 arguments, you can't know if that's 4 arrays, or 2 arrays
and 2 callbacks. Don't forget that array($class_name, $method_name) is a
valid callback, so you can't judge it by the type of the arguments either.
Regards,
--
Rowan Collins
[IMSoP]
Hi Rowan,
On Sun, Mar 8, 2015 at 3:35 AM, Rowan Collins rowan.collins@gmail.com
wrote:
We have a lot of array_u*() functions such as
http://php.net/manual/en/function.array-uintersect-uassoc.php
array array_uintersect_uassoc ( array $array1 , array $array2 [, array
$...
], callable $value_compare_func , callable $key_compare_func )
this can be consolidated to
http://php.net/manual/en/function.array-intersect-assoc.php
array array_intersect_assoc ( array $array1 , array $array2 [, array $...
]
)All of these has callback the end of parameters. These may be
consolidated.
I'll add this to the RFC if this is preferred.Those functions both take any number of arguments, so given a function
call with 4 arguments, you can't know if that's 4 arrays, or 2 arrays and 2
callbacks. Don't forget that array($class_name, $method_name) is a valid
callback, so you can't judge it by the type of the arguments either.
Thank you for heads up. If I detect array($class_name, $method_name) as
callback, there could
be unintended callback calls.
Since we have been deprecated similar
call_user_method()/call_user_method_array(), we may
deprecate array callbacks for u* functions, then consolidate in the future,
perhaps PHP8.
I don't mind add this to the RFC.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Rowan,
On Sun, Mar 8, 2015 at 3:35 AM, Rowan Collins rowan.collins@gmail.com
wrote:We have a lot of array_u*() functions such as
http://php.net/manual/en/function.array-uintersect-uassoc.php
array array_uintersect_uassoc ( array $array1 , array $array2 [,
array
$...
], callable $value_compare_func , callable $key_compare_func )
this can be consolidated to
http://php.net/manual/en/function.array-intersect-assoc.php
array array_intersect_assoc ( array $array1 , array $array2 [, array
$...
]
)All of these has callback the end of parameters. These may be
consolidated.
I'll add this to the RFC if this is preferred.Those functions both take any number of arguments, so given a
function
call with 4 arguments, you can't know if that's 4 arrays, or 2 arrays
and 2
callbacks. Don't forget that array($class_name, $method_name) is a
valid
callback, so you can't judge it by the type of the arguments either.Thank you for heads up. If I detect array($class_name, $method_name) as
callback, there could
be unintended callback calls.Since we have been deprecated similar
call_user_method()/call_user_method_array(), we may
deprecate array callbacks for u* functions, then consolidate in the
future,
perhaps PHP8.
I don't mind add this to the RFC.
What? That's not the same thing at all. I'm pretty sure those functions are deprecated because we have array callback forms, so you can use call_user_func to call a method.
PHP has a well-defined definition of "callable", as used by is_callable()
and function parameter typehints, and literally everywhere that wants a callback. Since there's no such thing as a function or method pointer, that definition includes a string identifying a plain function, and two array forms, [string, string] and [object, string], representing static and instance methods, respectively. You can't not accept those forms as a callback parameter in one particular function just to make things tidier.
Regards,
Rowan Collins
[IMSoP]
Hi Rowan,
On Sun, Mar 8, 2015 at 8:31 AM, Rowan Collins rowan.collins@gmail.com
wrote:
What? That's not the same thing at all. I'm pretty sure those functions
are deprecated because we have array callback forms, so you can use
call_user_func to call a method.PHP has a well-defined definition of "callable", as used by
is_callable()
and function parameter typehints, and literally everywhere that wants a
callback. Since there's no such thing as a function or method pointer, that
definition includes a string identifying a plain function, and two array
forms, [string, string] and [object, string], representing static and
instance methods, respectively. You can't not accept those forms as a
callback parameter in one particular function just to make things tidier.
I should have written "Let deprecate all array callbacks" by document and
raise deprecate error in PHP7.
Remove array callbacks in PHP 8.
Makes sense?
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Rowan,
On Sun, Mar 8, 2015 at 8:31 AM, Rowan Collins <rowan.collins@gmail.com
mailto:rowan.collins@gmail.com> wrote:What? That's not the same thing at all. I'm pretty sure those functions are deprecated *because* we have array callback forms, so you can use call_user_func to call a method. PHP has a well-defined definition of "callable", as used by `is_callable()` and function parameter typehints, and literally everywhere that wants a callback. Since there's no such thing as a function or method pointer, that definition includes a string identifying a plain function, and two array forms, [string, string] and [object, string], representing static and instance methods, respectively. You can't not accept those forms as a callback parameter in one particular function just to make things tidier.
I should have written "Let deprecate all array callbacks" by
document and raise deprecate error in PHP7.
Remove array callbacks in PHP 8.
In favour of what? We have no other way of telling a function expecting
a callback to use an existing method.
And why? Because one particular function signature you want to create
would be possible if "array" and "callback" were non-overlapping type
hints? Is there something wrong with having a function that explicitly
tells people it takes callbacks, rather than guessing based on the
arguments you pass in?
Regards,
--
Rowan Collins
[IMSoP]