How to call a method?

There is a file Registration.php content
require 'Db.php';

class Registration {

 public function Registr() {
 if(isset($_POST['btn'])) {
 if(isset($_POST['nickname']) && isset($_POST['email']) && isset($_POST['password']) !== ") {
 $dbh = DB::getConnect();
 $sql = 'INSERT INTO users (nickname, email, password) VALUES (:nickname, :email, :password)';
 $sqlParams = [':nickname' => $_POST['nickname'], ':email' => $_POST['email'], ':password' => $_POST['password']];
 $sth = $dbh->prepare($sql);
 $sth->execute($sqlParams); 
}
}
}

}


There is a second file Index.php I connect the file Registration and call the Registr

require_once 'Registration.php';

$registration = new Registration();
$registration->Registr();

require_once 'View/view.php';


Method why it does not work out, BUT, the method works correctly if you write so, that is, to call in the file Registration.php

require 'Db.php';

class Registration {

 public function Registr() {
 if(isset($_POST['btn'])) {
 if(isset($_POST['nickname']) && isset($_POST['email']) && isset($_POST['password']) !== ") {
 $dbh = DB::getConnect();
 $sql = 'INSERT INTO users (nickname, email, password) VALUES (:nickname, :email, :password)';
 $sqlParams = [':nickname' => $_POST['nickname'], ':email' => $_POST['email'], ':password' => $_POST['password']];
 $sth = $dbh->prepare($sql);
 $sth->execute($sqlParams); 
}
}
}

}

$registration = new Registration();
$registration->Registr();


In what place go wrong? After all, you want from the index to cause, and did
April 4th 20 at 00:45
1 answer
April 4th 20 at 00:47
set class autoloader? spl_autoload_register

Find more questions by tags PHP