Skip to content

Instantly share code, notes, and snippets.

@victorknust
Last active October 31, 2016 19:09
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 victorknust/45ce2e43d7b3236a32e2 to your computer and use it in GitHub Desktop.
Save victorknust/45ce2e43d7b3236a32e2 to your computer and use it in GitHub Desktop.
<?php
class Generica {
private $dados = array();
public function __set( $chave, $valor ) {
$this->dados[$chave] = $valor;
}
public function __get( $chave ) {
if ( !$this->__isset( $chave ) ) {
return null;
}
return $this->dados[$chave];
}
public function __isset( $chave ) {
return isset( $this->dados[$chave] );
}
public function __unset( $chave ) {
if ( !$this->__isset( $chave ) ) {
return null;
}
unset( $this->dados[$chave] );
}
public function __call( $metodo, $valor = null ) {
$prefixo = strtolower(substr($metodo, 0, 3));
$chave = substr($metodo, 3);
$chave = lcfirst($chave);
if ($prefixo == 'get') {
$this->__get( $chave );
} else if ($prefixo == 'set') {
if (count($valor) <= 1) {
$valor = $valor[0];
}
$this->__set( $chave, $valor );
} else {
throw new \Exception("");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment