I'm studying PHP and I came across the following question: what would be the difference between the following codes:
<?php
class ClasseTeste
{
protected $db_host = 'localhost';
protected $db_user = 'root';
protected $db_pass = 'root';
protected $db_name = 'bd_nome';
public function hello()
{
echo $this->db_host;
}
}
And this:
<?php
class ClasseTeste
{
protected function __construct()
{
$this->db_host = 'localhost';
$this->db_user = 'root';
$this->db_pass = 'root';
$this->db_name = 'bd_nome';
/**
* Gostaria de saber se eu poderia tambem definir o tipo dos campos dentro da funcao __construct(). Dessa maneira:
*
* private $this->db_host = 'localhost';
* private $this->db_user = 'root';
* private $this->db_pass = 'root';
* private $this->db_name = 'db_name';
*/
}
public function hello()
{
echo $this->db_host;
}
}