简体   繁体   中英

Class not found

I got the following error during I call the class (in image file) enter image description here

The following is the page I getting error. I'm trying to call the class from models/toSession.php .

<?php
session_start();
error_reporting(E_ALL^E_NOTICE);

use myGuzzle\myGuzzle;
use models\toSession;
spl_autoload_register(function ($class_name) {
    include $class_name . '.php';
});
session_start();
error_reporting(E_ALL^E_NOTICE);
$login = $_POST['login'];
$pass = $_POST['pass'];

$myGuzzle = new myGuzzle();
$myGuzzle->response(['login'=>$login,'pass'=>$pass,'rememberme'=>''],'POST','api.hitbox.tv/auth/login');

if($myGuzzle->getStatus() == 200){

    $json = json_decode($myGuzzle->getBody(),true);
    $toSession = new toSession();

   if($toSession->toSession($json)){
     $_SESSION['msg'] = "Login Success";
   }

}
else if($myGuzzle->getStatus() == 400){

    $_SESSION['msg'] = "Fail to login due to invalid id or password. ".$myGuzzle->getBody();

}
else{

     $_SESSION['msg'] = $myGuzzle->getBody();
    }



?>

Following is the class I wanted to call. I'm trying to turn the array to session.

<?php;
namespace models;
session_start();
error_reporting(E_ALL^E_NOTICE);

class toSession{

    public $opts;

    function turnToSession($opts = []){

        $this->opts = $opts;
        return proceed();

    }
    function  proceed(){

        foreach($this->opts as $key=>$value){

            $_SESSION[$key]=$value;

        }

        return true;
    }


}

Is it possible, that the class is not recognized as a class and by that printed as text, because you have a semicolon after <?php; in your toSession.php ?

Also the function toSession is not in that class as I stated in my comment. Only turnToSession.

Sorry for my other answer, I deleted it. If the source code is shown the file must obviously habe been found by autoloader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM