0

i have a little syntax error which i'm not able to sort out, can anyone help ?

Syntax: enter image description here

Config Class: enter image description here

Error:

enter image description here

Rishabh Jain
  • 110
  • 9

3 Answers3

1

Do not instantiate private variables like that, you should only be using them for declaring properties and simple values.

You cannot declare a private variable (declaring them a return value from a static functions at least) like that, just do it in the constructor __construct() for the object. You will get the same error for any class you do with a private variable declaration like that and setting it as a return value for any function. Try running the below in PHPFiddle and you'll get the same error.

<?php
class A {
    private $hi = B::some_function('hi');
}

class B {
    public static function some_function(string) {
        return $string;
    }
}
?>

Instead do something like:

<?php
class A {
    private $hi;
    public function __construct()  {
        $this->hi = B::some_function('hi');
    }
}

class B {
    public static function some_function(string) {
        return $string;
    }
}
?>
q.Then
  • 2,743
  • 1
  • 21
  • 31
  • thanks alot, i've done in __construct() this with some other variables but never new it can generate an error thanks – Rishabh Jain Sep 04 '15 at 05:49
0

Your syntax is incorrect as I've seen in that picture, simply because you didn't have a closing bracket '}' for the class User.

Makudex
  • 1,042
  • 4
  • 15
  • 40
  • well i have the closing brackets and everything, if i do $_table = 'String' its working perfectly but not with Config::get Method – Rishabh Jain Sep 04 '15 at 04:12
  • correct me if i'm wrong but is that really $_seassionTable? I think that's the problem with your code. – Makudex Sep 04 '15 at 04:15
  • Please try to update your picture, because i think there are some things that you've already edited there like the one I've mentioned earlier, that I haven't seen any closing bracket in your class User. – Makudex Sep 04 '15 at 04:17
  • no i haven't edited anything, and what you mean by $_seassionTable is a problem ?, and in users class there is much more code below, that's why you can not see the closing brackets. its a Portable library i'm working on, but this error stucks here. – Rishabh Jain Sep 04 '15 at 04:25
0

Just try this one. Use semicolon for every function call as shown below,

$_table = Config::get('tables/users');
$_seassionsTable = Config::get('tables/user_sessions');

It may be fix your issue.

Vignesh Bala
  • 889
  • 6
  • 25
  • no this won't work, syntax in not wrong the way you think. i'm declaring multiple variables so it needs ',' for separation not ';' – Rishabh Jain Sep 04 '15 at 05:54