What should I do to display the get return of the class in PHP?

0

I have the following code in PHP:

<!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 does not work and the browser warns that the getName function is undefined. But when I do this:

<?
...
 $x=$UserNow->getName();

    echo  "
    $x

     ";
  ?>

so it works . But I do not want to have to create temporary variables every time I use a class. What should I do to display the get get of the class?

    
asked by anonymous 01.06.2017 / 21:29

1 answer

2

remove the quotation marks inside your echo

edit:

Or

$x=$UserNow->getName();

echo $x;
    
01.06.2017 / 21:29