Created
March 31, 2023 13:27
-
-
Save wesllycode/6644f11f904d808182ef68a718935b03 to your computer and use it in GitHub Desktop.
Explicando uso do __construct com PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Como seria normalmente a criação de um objeto sem o construct. | |
Class Pessoa | |
{ | |
public function Nome(String $nome) :String | |
{ | |
return print $nome; | |
} | |
} | |
$pessoa = new Pessoa(); | |
$pessoa->Nome('Weslly - '); | |
// Como seria normalmente a criação de um objeto com o construct. | |
Class Identificacao | |
{ | |
public String $nome; | |
public function __construct(String $nome) | |
{ | |
return print $this->nome = $nome; | |
} | |
} | |
// Principal diferença que você já passa o parâmetro na hora que instancia o objeto. | |
$Homem = new Identificacao('Code'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment