d3no d3no - 1 year ago 52
PHP Question

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 .


use myGuzzle\myGuzzle;
use models\toSession;
spl_autoload_register(function ($class_name) {
include $class_name . '.php';
$login = $_POST['login'];
$pass = $_POST['pass'];

$myGuzzle = new myGuzzle();

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

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

$_SESSION['msg'] = "Login Success";

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

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


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


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

namespace models;

class toSession{

public $opts;

function turnToSession($opts = []){

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

function proceed(){

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



return true;


Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download