Welcome! Log In Create A New Profile

Advanced

[PHP] More operators

Posted by Sam Hobbs 
Sam Hobbs
[PHP] More operators
December 20, 2016 06:50AM
In addition to the "->" and "::" operators, the following probably need
more documentation too. I will list them followed by a comment in a
separate line for each; note that "{$" and "${" are two operators
(experienced PHP programmers know that I am sure).

=>
described in Array Operators but not in the table at the top of that page

()
not mentioned in "Array Operators", but is an operator for arrays, correct?

()
type-casting; not described as an operator

()
precedence; described in "Operator Precedence" but "()" is not described
as an operator or operators but probably should be

{$ and ${
undocumented, barely described and they need better names

....

called a token in "Function arguments" so it is not clear to me that it
is an operator but "..." seems to have multiple uses, none adequately
documented.


Note that also the "Assignment Operators" page has a note written 12
years ago saying it "ought to have table of assignment operators".
Christoph M. Becker
[PHP] Re: More operators
December 20, 2016 02:40PM
On 20.12.2016 at 06:47, Sam Hobbs wrote:

> In addition to the "->" and "::" operators, the following probably need
> more documentation too. I will list them followed by a comment in a
> separate line for each; note that "{$" and "${" are two operators
> (experienced PHP programmers know that I am sure).
>
> =>
> described in Array Operators but not in the table at the top of that page

I'm not sure whether => should be regarded an operator. It appears to
be rather a syntactic token for array-element-initializer[1] and
foreach-key[2].

> ()
> not mentioned in "Array Operators", but is an operator for arrays, correct?

Do you mean [] and/or {}? These are called subscript operator by the
PHP language specification[3].

> ()
> type-casting; not described as an operator

These are listed in the operator precedence table (`(unset)`, `(binary)`
and the aliases are missing, though), so should probably also be
described in the operator section.

> ()
> precedence; described in "Operator Precedence" but "()" is not described
> as an operator or operators but probably should be

What is descibed in the "Operarator Precedence" section is the use of
parens to enforce a certain order of evaluation. That is not an
operator, though. The function call operator[4] appears to be not
documented in the "Operators" chapter.

> {$ and ${
> undocumented, barely described and they need better names

I'm not sure whether these should be called operators at all, because
they're only used inside string literals

> ....
>
> called a token in "Function arguments" so it is not clear to me that it
> is an operator but "..." seems to have multiple uses, none adequately
> documented.

In my opinion, this is not an operator. The usage is documented in the
"Variable-length argument lists" section[5].

> Note that also the "Assignment Operators" page has a note written 12
> years ago saying it "ought to have table of assignment operators".

Patches are certainly welcome! For instance, via https://edit.php.net/.

[1]
<https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#array-creation-operator>;
[2]
<https://github.com/php/php-langspec/blob/master/spec/11-statements.md#the-foreach-statement>;
[3]
<https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#subscript-operator>;
[4]
<https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#function-call-operator>;
[5]
<http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list>;

--
Christoph M. Becker

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Alain Williams
Re: [PHP] Re: More operators
December 20, 2016 02:50PM
On Tue, Dec 20, 2016 at 02:31:44PM +0100, Christoph M. Becker wrote:

> I'm not sure whether => should be regarded an operator. It appears to
> be rather a syntactic token for array-element-initializer[1] and
> foreach-key[2].

It doesn't really matter if it is/is-not an operator; people will expect to find
it documented in the list of operators --- the explanation might well start by
saying that it is not an operator.

--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login