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

Asked

Viewed 40 times

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();

  • 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.

1 answer

2


remove the quotes inside your echo

Edit:

Or

$x=$UserNow->getName();

echo $x;
  • ual! Thank you very much :D

  • for nothing, if I can vote on the answer and mark it as correct, I thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.