I'm very new to PHP, and I can't solve an issue even I read a lot of tutorials and SO posts. I've a custom class (user), and I'd like to instantiate it in php code, but even I include it, I get this error.
Fatal error: Class 'User' not found in D:\wamp64\www\MyFirstPhp\formPhp.php on line 17
Please help me find out what I do wrong.
Here is my user class:
<?php
/**
* Created by IntelliJ IDEA.
* User: molnard
* Date: 2017. 06. 06.
* Time: 15:36
*/
namespace infopro;
class User
{
private $username;
private $userage;
private $sex;
public function __construct($username, $userage, $sex)
{
if (!is_null($username)) $this->username = $username;
if (!is_null($userage)) $this->userage = $this->userage;
if (!is_null($sex)) $this->sex = $sex;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* @return mixed
*/
public function getUserage()
{
return $this->userage;
}
/**
* @param mixed $userage
*/
public function setUserage($userage)
{
$this->userage = $userage;
}
/**
* @return mixed
*/
public function getSex()
{
return $this->sex;
}
/**
* @param mixed $sex
*/
public function setSex($sex)
{
$this->sex = $sex;
}
}
?>
And here is my form.php class where I'd like to instantiate user class.
<!Doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Form php</title>
</head>
<body>
<?php
include("User.php");
$name = $_POST["name"];
$age = $_POST["age"];
$sex = $_POST["sex"];
echo "New user<br>name: " . $name . "<br>" .
"age: " . $age . "<br>" . "sex: " . $sex."<br>";
$newuser = new User($name, $age, $sex);
$newAge = $newuser->getAge();
echo $newAge;
?>
</body>
</html>