PHP - Fatal error: Unsupported operand types

前端 未结 5 1425
别跟我提以往
别跟我提以往 2020-12-19 07:59

I keep getting the following error and I was wondering on how to fix?

Fatal error: Unsupported operand types in C:\\wamp\\www\\tuto\\core\\Controller.php on          


        
相关标签:
5条回答
  • 2020-12-19 08:37

    **PROBLEM YOUR FAILED TO ADDED EQUAL SIGN TO THE VARIABLE WHICH FETCH INFORMATION TO THE DATABASE **

    Hell guys i tried to remove PHP - Fatal error: Unsupported operand types this error will occur during us fail to declare the variable correct so you will solve it this error by add the sign "=" Example if you try to type like this:

    $sa="SELECT * FROM `anquiz` WHERE user_id = $a";
    $af=mysql_query($sa); 
    while($cv-mysql_fetch_array($af)){
        $d1=$cv['id'];
        $d2=$cv['answer'];//student answer
        $d4=$cv['quiz_id'];// quiz id 
        $d5=$cv['user_id'];// user id insert his file
        $d6=$cv['time'];
    

    you will get error of fatal unsupported operand by sign - on varible that carry the mysql_fetch_array instead of adding = Take that example` by adding that sign you will see an error

    0 讨论(0)
  • 2020-12-19 08:39

    + can be used in different ways but to avoid complications, only use it on numeric values.

    When you didnt initially set $this->vars to be an array, it won't work (thx to deceze); see http://codepad.viper-7.com/A24zds

    Instead try init the array and use array_merge:

    public function set($key,$value=null){
        if (!is_array($this->vars)) {
            $this->vars = array();
        }
    
        if(is_array($key)){
            $this->vars = array_merge($this->vars, $key);
        }else{
            $this->vars[$key] = $value;
        }
    }
    

    Examples:

    <?php
    $test = null;
    
    $t    = array('test');
    
    //$test += $t prints the fatal here
    
    $test = array('one');
    
    $test += $t;
    
    // will only print '0 => one'
    print_r($test);
    
    
    $test = array_merge($test, $t);
    
    // will print both elements
    print_r($test);
    
    0 讨论(0)
  • 2020-12-19 08:42

    The problem of fatal error unsupported operand type is cause by failing to add the equal sign to the mysql fetch array after variable. Try this write the statement like that and use these examples like adding - or _ You will see fatal error.

    $query=mysql_query("SELECT * FROM user");
    $fetch=mysql_fetch_array($query);
    
    0 讨论(0)
  • 2020-12-19 09:01

    The solution is in the error. You are trying to sum two value that has different types. You are summing array with normal value;

    $this->vars +=  $key;
    

    $key shouldnt be an array

    Or second option;

    $this->vars should be an array

    0 讨论(0)
  • 2020-12-19 09:04
    1. $this->vars,
    2. this->$vars,
    3. $this->$vars.

    Only number 1 is correct, 2 & 3 are not

    0 讨论(0)
提交回复
热议问题