0
I have the following PHP code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
include '../model/class/classUser.php';
$UserNow = new User();
$UserNow->setName(htmlspecialchars($_POST['name']));
$UserNow->setUsername(htmlspecialchars($_POST['username']));
$UserNow->setYourOcupation(htmlspecialchars($_POST['yourOcupation']));
$UserNow->setYourGraduation(htmlspecialchars($_POST['yourGraduation']));
$UserNow->setEmail(htmlspecialchars($_POST['email']));
$UserNow->setPassword(htmlspecialchars($_POST['password']));
$RPassword=htmlspecialchars($_POST['rPassword']);
$x=$UserNow->getName();
echo "
$UserNow->getName();
";
?>
</body>
</html>
The code doesn’t work and the browser warns that the getName function is undefined. But when I do it:
<?
...
$x=$UserNow->getName();
echo "
$x
";
?>
then he works. But I don’t want to have to create temporary variables every time I use a class. What should I do to display the return of the get class?
Take the quotes from your echo. For example echo $userNow->getName();
– UzumakiArtanis
Sergio, I noticed your questions don’t have any accepted answers. To warn you: you can choose an answer (only one) as correct for each question you ask, this is done through ✓ on the left side of the answer.
– Jéf Bueno