-1
Talk guys, all beauty?
I am studying Interfaces in PHP and am having an error invoking the Setter method in my attributes.
<!-- User Interface -->
<?php
session_start();
interface User {
public function userName($uName);
public function userEmail($uMail);
public function userPasswd($uPass);
}
class Cliente implements User{
private $userName;
private $userEmail;
private $userPasswd;
/**
* Get the value of userName
*/
public function getUserName()
{
return $this->userName;
}
/**
* Set the value of userName
*
* @return self
*/
public function setUserName($userName)
{
$this->userName = $userName;
return $this;
}
/**
* Get the value of userEmail
*/
public function getUserEmail()
{
return $this->userEmail;
}
/**
* Set the value of userEmail
*
* @return self
*/
public function setUserEmail($userEmail)
{
$this->userEmail = $userEmail;
return $this;
}
/**
* Get the value of userPasswd
*/
public function getUserPasswd()
{
return $this->userPasswd;
}
/**
* Set the value of userPasswd
*
* @return self
*/
public function setUserPasswd($userPasswd)
{
$this->userPasswd = $userPasswd;
return $this;
}
public function userName($uName)
{
$this.setUserName($uName);
echo "<br>".
"<p>Nome:".getUserName()."</p>";
}
public function userEmail($uMail)
{
$this.setUserEmail($uMail);
echo "<br>".
"<p>Email:".getUserEmail()."</p>";
}
public function userPasswd($uPass)
{
$this.setUserPasswd($uPass);
echo "<br>".
"<p>Email:".getUserPasswd()."</p>";
}
}
$usuario = new Cliente();
if(isset($_POST["name"])){
$usuario->userName($_POST["name"]);
}
if(isset($_POST["email"])){
$usuario->userEmail($_POST["email"]);
}
if(isset($_POST["passwd"])){
$usuario->userPasswd($_POST["passwd"]);
}
?>
And the Error:
Fatal error: Uncaught Error: Call to undefined function setUserName() in D:\Programacao\Xampp\htdocs\PHP7\interface\exe02.php:79 Stack trace: #0
D:\Programacao\Xampp\htdocs\PHP7\interface\exe02.php(109): Cliente->userName('Vitor') #1 {main} thrown in D:\Programacao\Xampp\htdocs\PHP7\interface\exe02.php on line 79
I don’t think the error is related to the Interface, but I don’t understand it returning Undefined in an existing and Public method.
The data is coming from a form on another page, I believe is irrelevant to the problem.
Thanks for your attention
Incorrect syntax in some snippets. nothing else is ever used to invoke methods. "->" vc points and Svezes omits $this->
– Atila Silva
Yes, the answer below indicated me those syntax errors, but thanks anyway
– Vitor Couto