-1

Can anyone please help me, this function was working correct on my localhost but when i did site live i am facing this issue.

 private function _get_token( $userData = array() ) {
        $token = sha1(uniqid());

        $oldData = get_option(self::PREFIX .'data') ?: array(); //Error on this line
        $data = array();
        $data[$token] = $userData;
        update_option(self::PREFIX .'data', array_merge($oldData, $data));

        return $token;
    }
  • `?:` why both with each other?? – Murad Hasan May 27 '16 at 09:05
  • ternary operator syntax is : `$var = (5 > 2 ? true : false); // returns true` – Nehal May 27 '16 at 09:09
  • What's the PHP version on the server? According to the [documentation](http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary), leaving out the middle part of the ternary operator wasn't allowed before PHP 5.3. – Sébastien May 27 '16 at 09:16

1 Answers1

0

The issue is about ?:, This is the ternary operator, so you need to set the value of the condition when ture and also for false, In your case you just set the value for false.

This is your

$oldData = get_option(self::PREFIX .'data') ?: array();

Should Be:

$oldData = get_option(self::PREFIX .'data') ? get_option(self::PREFIX .'data') : array();

I think so, Let me know if this is the issue or not.

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42