Web lists-archives.com

[PHP] Re: More operators




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