In the context of the question would be the second option:
$atleta = new Atleta();
But remember that in PHP, it is not necessary to use parentesis ()
when the class has no constructor or does not need arguments.
Then that would also be valid:
$atleta = new Atleta;
Explanation of each option
I don’t know if I’m wrong, but the question sounds a lot like an evaluative question. So, assuming that, I don’t think it’s cool to just "give the right answer," but explain what each thing does.
$atleta = Atleta;
Generally, this syntax is used in PHP to get the value of a constant.
For example:
const Atleta = 'Atleta';
// ou
define('Atleta', 'Atleta');
$atleta = Atleta;
Observing: When trying to assign the value of an undefined constant, you will receive an error message of type E_NOTICE
and the value assigned will be a string as the name of the nonexistent constant.
$atleta= Atleta();
This syntax is used for the direct function call. Functions in PHP are called with the use of parentesis, can be passed arguments or not.
Example:
function Atleta() {
return 'Atleta';
}
$atleta = Atleta();
IS
$atleta= new Atleta();
– rray
Ah I prefer
$atleta = new Atleta();
.– Guilherme Lautert
@Tmc this edition made the title more confusing, it was already quite clear. So I reverted its edition to the previous one.
– user28595
@Articuno, I agree I went to review and made it more confusing
– Tmc
@Stormwind would only take the highlight of quote, which for this case would not even be necessary, but had not noticed that there were 3 forms, the edition was good.
– user28595