I'm starting in the world of POO with PHP. When accessing the properties of the object Persona
through a getter, its corresponding value does not appear.
The class code is as follows:
<?php
class Persona{
public $nombre;
public $apellido;
public $dni;
function setName($nombre){
$this -> nombre = $nombre;
}
function getName(){
return $this -> nombre;
}
}
?>
Then in another archivo.php
I create an object of that class and give it some values:
<?php
require_once("class.php"); // fichero de la clase anterior
$marcos = new Persona();
$marcos -> setName('Marcos');
$marcos -> getName();
?>
If I access this script in my browser I do not see anything at all. But if I modify the code and present it in the following way, it shows me on the Marcos screen.
<?php
require_once("class.php");
$marcos = new Persona();
$marcos -> setName('Marcos');
?>
<?=
$marcos -> getName();
?>
How is this? What is the difference between <?php ?>
and <?= ?>
?