0

i keep getting the error Parse error: syntax error, unexpected '['

for some strange reason and i really cant figure out why, heres my skype.class

    <?php

class SkypeResolver {
    function __construct($db) {
        $this->db = new DB($db);
    }
    function get_ip($username) {
        $str = $this->skypeurl();
        $str .= $username;
        $output = file_get_contents($str);
        return $output;
    }
    function skypeurl() {
        return $this->db->fetch_array($this->db->query("SELECT * FROM `settings` WHERE `ident`='skype-api-url'"))['val'];
    }
}
?>

ive tried removing the "[" but it then throws another error which i fix which then leads to another error and so on... anyone got any ideas ?

user2649305
  • 149
  • 9
  • 3
    Array dereferencing is supported from PHP 5.4 onwards. You need a workaround / temp var. – mario Aug 03 '13 at 20:12

3 Answers3

0

Like somebody said older PHP version. You need to do it the old way.

function skypeurl() {
$array = $this->db->fetch_array($this->db->query("SELECT * FROM `settings` WHERE `ident`='skype-api-url'"));
return $array['val'];
}
0

A possible solution:

function skypeurl() {
    $array = $this->db->fetch_array($this->db->query(\
        "SELECT * FROM `settings` WHERE `ident`='skype-api-url'"));
    return $array['val'];
}
Rubens
  • 14,478
  • 11
  • 63
  • 92
AmazingDreams
  • 3,136
  • 2
  • 22
  • 32
0

You have to use PHP 5.4 or higher to directly get array keys from functions. This is a workaround working on any version:

function skypeurl() {
    $res = $this->db->fetch_array($this->db->query("SELECT * FROM `settings` WHERE `ident`='skype-api-url'"));
    return $res['val'];
}
Jeroen
  • 15,257
  • 12
  • 59
  • 102