|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
Here is a small example i have come up with to show how easy it is to use
encapsulation with PHP 5.
NOTE - to make this really effective you should store tha app object in a session
variable so that the app object will not be reloaded every page load, it will retain
it's values through session.
NOTE - If you have objects that you wish to have re-created with every page load don't
define the variable as static, and dont check to see if the variable is null, just return
a new instance, remember when the app object is stored in session, so are the other objects
since they are defined static and the app object is not re-created from page to page.
The following code just shows how you can have the user object within the app object and still
call it's methods very easilly without ever having to do $user = $app->User();
| <?php
class App {
private static $_user;
public function User( ) {
if( $this->_user == null ) {
$this->_user = new User();
}
return $this->_user;
}
}
class User {
private $_name;
public function __construct() {
$this->_name = "Joseph Crawford Jr.";
}
public function GetName() {
return $this->_name;
}
}
$app = new App();
echo $app->User()->GetName();
?> | |
|
|
| SPL and ITERATOR : examples Categories : PHP, Object Oriented, PHP Classes, Sessions | | | Advanced Image WaterMarker Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented | | | Access_user Class - an easy to use system for protecting pages and register users. Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication | | | An updated OOP - Inheritance Categories : PHP, PHP Classes, Object Oriented | | | very simple ftp class Categories : PHP, PHP Classes, FTP | | | PHP Paypal IPN Integration Class v1.0.0 Categories : PHP, PHP Classes, Payment Gateways | | | A Timing Class Categories : PHP, PHP Classes, Date Time | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Create HTML forms dynamicly using Javascript & PHP Categories : PHP, PHP Classes, Java Script | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | RSS parser.
Parses RSS into an array. Quick and nasty but does the job.
No checking is done for correct Tags, only correct XML.
PHP4 needed to display result (uses print_r). Categories : PHP, XML, PHP Classes, Rich Site Summary (RSS) | | | These PHP Classes Check if a host is alive using various methods. Categories : PHP, PHP Classes, Sockets, CURL | | | an example of the cyberlib payment class Categories : PHP, PHP Classes, Ecommerce, Credit Cards | | | Power Form Validation Categories : PHP, PHP Classes, Data Validation | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | |
|
|
|