Skip to content

Instantly share code, notes, and snippets.

@Bolinha1
Created October 2, 2013 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Bolinha1/6798785 to your computer and use it in GitHub Desktop.
Save Bolinha1/6798785 to your computer and use it in GitHub Desktop.
autoload
<?php
// Your custom class dir
define('CLASS_DIR', 'classe/');
// Add your class dir to include path
set_include_path(get_include_path().PATH_SEPARATOR.CLASS_DIR);
// You can use this trick to make autoloader look for commonly used "My.class.php" type filenames
spl_autoload_extensions('.php');
// Use default autoload implementation
spl_autoload_register();
<?php
include 'autoload.php';
use classe\Usuario;
$u = new Usuario;
var_dump($u);
<?php
// dir classe/Usuario
namespace classe;
class Usuario
{
private $email;
private $senha;
public function setEmail($email)
{
$email = strtolower($email);
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
return false;
else
$this->email = $email;
}
public function getEmail()
{
return $this->email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment