PHP error Cannot use return> value method in write context

I get this error in a PHP class ...

Fatal error: you cannot use the method return value in the context of the entry in C: \ web server \ HTDOCS \ friendproject2 \ includes \ classes \ User.class.php on line 35

Here is the worried part.

if(isset($this->session->get('user_id')) && $this->session->get('user_id') != ''){
    //run code
}

This code is in my contrustor, this value is not set for $ this-> session-> get ('user_id') yet, then it will return false instead of Number. So, as you can see, I was hoping to check whether this number is a number or not or not even set.

Any help with fixation is appreciated.

+3
source share
3 answers

isset . :

if( $this->session->get('user_id') ){
    //run code
}
+14

isset() - . defined().

PHP.

+12

isset . , false, 0 '' false, :

if( $id = $this->sessions->get('user_id') ){
   // Will only run if $id does not equal '', False, or 0
}

, .

+1

Source: https://habr.com/ru/post/1728774/


All Articles