Skip to content

Instantly share code, notes, and snippets.

@airtonzanon
Last active October 18, 2016 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airtonzanon/683d71af2efd46bd2c7d9bb07a5506ee to your computer and use it in GitHub Desktop.
Save airtonzanon/683d71af2efd46bd2c7d9bb07a5506ee to your computer and use it in GitHub Desktop.
<?php
require_once 'PessoaModel.php';
// não há necessidade de passar os parâmetros por exemplo
$pessoa = new PessoaModel();
// mas tu vai ter que setar os atributos um por um
$pessoa->setNome('Foo');
$pessoa->setSexo('Masculino');
$pessoa->setIdade(50);
print_r($pessoa->toArray());
//Você também pode colocar os parâmetros na hora de instanciar
$pessoa = new PessoaModel('Foo', 'Masculino', 50);
print_r($pessoa->toArray());
<?php
class Pessoa {
private $nome;
private $sexo;
private $idade;
public function __construct($nome = null, $sexo = null, $idade = null){
$this->nome = $nome;
$this->sexo = $sexo;
$this->idade = $idade;
}
//getters e setters se necessario
//métodos
public function toArray(){
return get_object_vars($this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment