-4
How should I place the parameters inside the constructor’s parentheses?
I tried as follows as seen in videos but has the following error:
OBS.: I am using the terminal, I am using the file criando.php;
to expedite.
<?php
require 'Conta.php';
$novaConta= new Conta(cpf: '123.123.123-2', titular: 'David');
?>
You are showing the following error:
Interactive shell
php > require 'creating.php';
Parse error: syntax error, Unexpected ':', expecting ')' in C: meuphp Atom creating.php on line 6
The line 6 mentioned above is where I enter the data:
$novaConta= new Conta(cpf: '123.123.123-2', titular: 'David');
In the class that the object receives, the constructor is as follows:
<?php
class Conta{
private $cpf;
private $titular;
private $saldo;
public function __construct(string $cpf, string $titular){
$this->cpf=$cpf;
$this->titular=$titular;
$this->saldo=0;
}
}
?>
The version of my PHP is 7.4.
How to pass the value, because I saw in videos and that’s how they passed?
Where did you see this feature? in which video? can post along with the question?
– novic
It was on a course at Alura
– Medivh
but, is in PHP ?
– novic
Yes, it was in a PHP course.
– Medivh
So if you have to post this here, why have you already accepted the answer face-to-face if your question says otherwise? Because the answer you accepted is the normal of any language...
– novic
I don’t remember posting any link to the study material, I just specified where it was, if you don’t want the answer don’t ask.
– Medivh
What is the link to this video?
– Augusto Vasques
The question says video suppose link so we were curious to know where you saw this.
– novic