Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
976 views
in Technique[技术] by (71.8m points)

php - Terminology question on "dereferencing"?

In PHP, the following code is valid

$a=array(0);$a[0];

but that one is invalid:

array(0)[0]
  1. What is the terminology corresponding to that behaviour? (has it anything to do with "dereferencing"?)
  2. What is the motivation behind such a behaviour (besides user spite :-P)

I am looking for the general terminology, not necessarily the terminology associated with PHP.

(Other example: in MATLAB, the following is valid:

s = size(M)
s(0)

but that is invalid:

size(M)(0)

In both PHP and MATLAB, adding parenthesis does not help, i.e., (array(0))[0] and (size(M))(0) are both invalid)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That's called Array dereferencing, and will become available in PHP 5.4 (which is currently in alpha)

Note (thanks Gordon) : what you are asking for, with array()1, is not possible even in PHP 5.4 -- but it'll work for functions.


A couple of sources :


Quoting that last news :

Here is an incomplete list of changes:
- Added: Traits language construct
- Added: Array dereferencing support
- Added: DTrace support
- Improved: Improved Zend Engine memory usage and performance
- Moved: ext/sqlite moved to pecl (sqlite3 support is still built-in)


1.array() is not a function, even if it looks like one -- it's actually what PHP calls a language construct ; and those don't behave like functions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...