1

The code is

// Get singleton (first value from row with single value)
static function singleton($arg, $params = false) {
    return pg_fetch_row(SQL($arg, $params))[0];
}

The error message is

2014-02-19 12:54:23: (mod_fastcgi.c.2701) FastCGI-stderr: PHP message: PHP Parse error: syntax error, unexpected '[' in /var/www/blockexplorer.com/htdocs/includes/sql.inc on line 69

I think there is a config that can fix it.

3
  • 2
    What is the version of your PHP you using ? Commented Feb 19, 2014 at 6:21
  • It seems like a PHP5.3, that not supports this. So, you need to place result of function pg_fetch_row into variable first - as @Mario Jonathan calls it. Commented Feb 19, 2014 at 6:26
  • Your syntax is correct, but that's a very new feature of PHP that (IIRC) requires at least version 5.4. I can't find it in the change logs, but it's better (for now) to count on that not working unless your developing for a specific platform. Commented Feb 19, 2014 at 6:27

3 Answers 3

4

This depends on PHP version you are using. If you are using PHP 5.4 or above then your code will not give error otherwise you will have to store the result in a variable and use it.

Reference : PHP 5.4

Look for "Array Dereferencing" here.

Sign up to request clarification or add additional context in comments.

Comments

2

Put the result of the function in a variable

static function singleton($arg, $params = false) {
    $foo = pg_fetch_row(SQL($arg, $params));
    return $foo[0];
}

Comments

0

PHP does not support anonymous arrays. Use an named array instead:

static function singleton($arg, $params = false) {
    $row=pg_fetch_row(SQL($arg, $params));
    return $row[0];
}

1 Comment

Array dereferencing is supported by PHP, but only in 5.4+.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.