Created
October 2, 2013 18:59
-
-
Save Bolinha1/6798785 to your computer and use it in GitHub Desktop.
autoload
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 | |
// 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(); |
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 | |
include 'autoload.php'; | |
use classe\Usuario; | |
$u = new Usuario; | |
var_dump($u); |
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 | |
// 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