0

I am running Aptana Studio 3, build: 3.6.1.201410201044. I don't understand why it is reporting the following as a syntax error given that it was working fine in vim and could run the code in XAMPP with no errors:

$key = array_keys($myArray)[0];

Why is Apatana reporting a syntax error here and how do I fix it?

John Sonderson
  • 2,852
  • 6
  • 26
  • 41
  • 1
    It's called array dereferencing. it's only available in 5.4+, so I'd suspect, either your local version of PHP isn't that high, or Aptana has its own parser that doesn't know about it. (Never used Aptana). – Jonnix Sep 08 '15 at 15:46
  • As of today I am running the latest version of XAMPP with PHP Version 5.6.11 as well as the latest version of Aptana Studio 3. I guess Aptana has some catching up to do. Anyways, isn't array dereferencing simply accessing an array element with the square brackets notation? If not, then what is the problem? And how do I fix it in Aptana Studio 3? – John Sonderson Sep 08 '15 at 15:48
  • 1
    No, use of the square brackets is simply array access generally, until 5.4, it had to be used on an array, it could not be used against a function / method call whether or not that call returned an array. – Jonnix Sep 08 '15 at 15:50

2 Answers2

0

The problem with the code is that Aptana 3 does not support some syntax available in new versions of PHP. To fix it in Aptana, do the following:

$keys = array_keys($myArray);
$key = $keys[0];

Alternatively, switch to another IDE such as for instance the PHP version of eclipse, and read this thread to get started.

Community
  • 1
  • 1
John Sonderson
  • 2,852
  • 6
  • 26
  • 41
  • 2
    Just sayin', but personally, having to modify your code to match the syntax of an EOL version of PHP for the sake of an IDE doesn't sound much like a fix to me. *shrug* – Jonnix Sep 08 '15 at 15:58
  • Yes, it's true. I'm going to try and install the PHP version of eclipse and see if that works. – John Sonderson Sep 08 '15 at 16:12
0

On Apatana Studio 3, right click your project. Click "Properties" from the drop down menu. Go to "PHP Development" then select PHP 5.4x or higher.

Tunaki
  • 116,530
  • 39
  • 281
  • 370
Jhourlad Estrella
  • 3,275
  • 3
  • 31
  • 56