|
|
|
| Title : |
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects. |
| Categories : |
PHP, PHP Classes, Algorithms |
 Alix Axel |
| Date : |
Apr 28th 2009 |
| Grade : |
1 of 5 (graded 1 times) |
| Viewed : |
2712 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Alix Axel |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
|
|
|
|
Like this code?
Show the author your appreciation.
|
| |
This function also sets you free from include/require(_once)'s.
| <?php
function Object($object)
{
static $result = array();
if (class_exists($object, false) === true)
{
if (array_key_exists($object, $result) === false)
{
$result[$object] = new $object();
}
return $result[$object];
}
else if (is_file('./' . $object . '.php') === true)
{
$class = basename($object);
if (array_key_exists($class, $result) === false)
{
if (class_exists($class, false) === false)
{
require('./' . $object . '.php');
}
$result[$class] = new $class();
}
return $result[$class];
}
return false;
}
?> | |
Usage:
| <?php
Object('path/to/your/class')->yourClassMethod();
// now that your class is loaded we don't need to specify it's path
Object('class')->yourClassMethod();
// Example:
Object('libraries/DB')->Connect('name', 'user', 'pass', 'host');
Object('DB')->Query('SELECT * FROM users;');
?> | | |
|
| Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags. Categories : PHP, PHP Classes, Algorithms, Security | | | Credit Card Identification and Validation Class - The credit_card class provides methods for cleaning, validating and identifying the type of credit card numbers. Categories : PHP, PHP Classes, Credit Cards, Ecommerce, Algorithms | | | A class to put get and post variables in hidden form
elements. Works on scalars, normal arrays, associative
arrays. Categories : Algorithms, Variables, Arrays, PHP, PHP Classes | | | Timer - a class that uses microtime() to provide easy calculation of elapsed times Categories : Algorithms, PHP, PHP Classes | | | A class for sending email; it has support for To:, Cc:, Bcc: and Reply-To:
headers. It requires that you have sendmail installed. Categories : Email, PHP Classes, PHP | | | Three Cool Classes and One Trick Categories : PHP, PHP Classes, Graphics, Email | | | ADODB Database Wrapper Abstraction Library for PHP: MySQL, MSSQL,
Oracle, Interbase,ODBC, Microsoft Access and FoxPro. Categories : PHP Classes, Databases, PHP, General SQL, ODBC | | | Specify your connection settings and create a link to a MySQL database. Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides | | | Automatic generation of HTML code for a table. OO interface. Can define colspan, rowspan, table style, cell style, and data style. Simple, but
effective. Categories : PHP, PHP Classes, HTML, HTML and PHP | | | Mssql database Manager Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes | | | PHP MIME Decoder. This class decodes Mime Encoded email message.
Attachments are stored in a director. Works with Multipart/alternative,
multipart/mixed etc.
see http://p3mail.com for example. Categories : PHP, PHP Classes, Email | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | quick sort for associative arrays Categories : Algorithms, Arrays, PHP | | | crop and resize image class using gd library function Categories : PHP, PHP Classes, GD image library, Graphics | |
| |
| |
|