Bbeni
Bbeni

Reputation: 75

autoload.php class not found

I'm usually programming in java language , but now i have to know the oop php. I made a sample project for myself for practice , but it doesn't work. I need some help what did i do wrong. Here is my 3 php files.

Index.php

<?php

require_once 'classes/Autoload.php';

$person = new Person();
$person->setName('asd');
$person->getName();?>

Person.php

<?php
    class Person{

        private $name ;
        private $age



        public function setName($name){
            $this->name = $name;

        }


        public function getName(){
            echo $this->name."<br>";

        }


    }

and here is the autoload.php

<?
function _autoload($class){
        include 'classes/'.$class .'.php';

    }

    spl_autoload_register('autoload');

?>

I hope somebody can help me and I'll understand it. Thank you.(Please don't say to me "I'm noob" if I did big stupid thing, I'm beginner and I'd like to learn it. )

Upvotes: 2

Views: 104

Answers (1)

Marc B
Marc B

Reputation: 360562

it's __autoload (TWO underscores). you have _autoload (ONE underscore):

function _autoload($class){
         ^---

Upvotes: 2

Related Questions