0
I’m making an object-oriented system with php and I noticed that the following code does not work:
<?php
include 'User.php';
$temp_user = new User();
$temp_user->set_name(htmlspecialchars($_POST['name']));
$temp_user->set_user_name(htmlspecialchars($_POST['username']));
$temp_user->set_password(htmlspecialchars($_POST['password']));
//$local_name= $temp_user->get_name();
echo "<br>$temp_user->get_password()<br>"
?>
But the same code without sending directly the class method works:
include 'User.php';
$temp_user = new User();
$temp_user->set_name(htmlspecialchars($_POST['name']));
$temp_user->set_user_name(htmlspecialchars($_POST['username']));
$temp_user->set_password(htmlspecialchars($_POST['password']));
//$local_name= $temp_user->get_name();
$var1 = $temp_user->get_password();
echo "<br>$var1<br>"
. "<br><br>"
. "<br><br>";
?>
What could be wrong?
NOTE: all my methods are public
Try to put keys in the first code:
{$temp_user->get_password()}
– Woss
In the first code. Or do so:
echo "<br>".$temp_user->get_password()."<br>"
– Francisco
Within the
echo
. Something likeecho "<br>{$temp_user->get_password()}</br>"
– Woss