WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Encapsulation with PHP 5
Categories : PHP, PHP Classes, Object Oriented Click here to Update Your Picture
Joseph Crawford
Date : Jan 15th 2005
Grade : 3 of 5 (graded 2 times)
Viewed : 21411
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Joseph Crawford
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
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
An updated OOP - Inheritance
Categories : PHP, PHP Classes, Object Oriented
Football News Aggregator
Categories : PHP, Object Oriented, PHP Classes, Rich Site Summary (RSS), HTML and PHP
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
My Box - PHP Class that calculates the volumetric weight of a package.
Categories : PHP, Object Oriented, PHP Classes, Beginner Guides, Payment Gateways
EasyPhpThumbnail Class - The EasyPhpThumbnail class allows you to generate thumbnails and handle image manipulation for GIF, JPG and PNG on-the-fly.
Categories : PHP, PHP Classes, Object Oriented, Graphics, GD image library
Access_user Class - an easy to use system for protecting pages and register users.
Categories : PHP, Classes and Objects, Object Oriented, PHP Classes, Authentication
.htpassword manager for apache
Categories : PHP, PHP Classes, Authentication, Apache
Freshmeat.net XML-RPC - This class is meant to query Freshmeat for information about registered projects.
Categories : PHP, PHP Classes, XML, Web Services
Blueshoes PHP Application Framework
Categories : PHP, Frameworks, PHP Classes
Power Form Validation
Categories : PHP, PHP Classes, Data Validation
Class to convert any document, that can be read by MS Word, to another format supported by Word.
Categories : PHP Classes, PHP, Windows 2000, Microsoft Word, WinNT
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Sample usage of IPv6 and IPv4 with PHP
Categories : PHP, PHP Classes, Network