WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
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
Submit Site
Forex Trading Online forex trading platform

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 : PHP5 and __get and __set
Categories : PHP, PHP Classes Click here to Update Your Picture
Joseph Crawford
Date : Aug 30th 2004
Grade : 3 of 5 (graded 6 times)
Viewed : 7862
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

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

_get and _set are new features to php5. when you use $obj->propertyName if the property was not defined in the class like :

<?php
private $propertyName;
?>


then it get's added to the $properties property, which is an array.

so if i do

<?php
$test
->MyProp = "testing";
?>


and there is not a $MyProp; defined in the class then it pushes it to the properties array like so

<?php
array (
'MyProp' => "testing",
);
?>


also when i do :

<?php
echo $test->MyProp;
?>


because there is not a property named MyProp defined it checks the properties array for the value.

these are some nice functions, if you have never read about them this will show you an easy way to keep a site configuration or something else useful :

<?php
class Test {
  var
$properties;
  function
__set($property_name, $val) {
   
$this->properties[$property_name] = $val;
  }
   
  function
__get($property_name) {
    if(isset(
$this->properties[$property_name])) {
      return(
$this->properties[$property_name]);
    } else {
      return(
NULL);
    }
  }
}


Usage Example
<?php
//There's the class now let's see it in use

$t = new Test();
$t->MyProp = "Property1";
echo
$t->MyProp;

/*
when you print_r the object you will see these results

Test Object
(
  [properties] => Array
  (
    [MyProp] => Property1
  )
)
*/
?>

notice how MyProp was turned into an array key Maybe now you can see how usefull these 2 functions really are ;)

Combine this with the code example i did about Singleton Patterns and PHP5 and you have a good start to a nice object design.



very simple ftp class
Categories : PHP, PHP Classes, FTP
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
Create HTML forms dynamicly using Javascript & PHP
Categories : PHP, PHP Classes, Java Script
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
usercounter class
Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables
These PHP Classes Check if a host is alive using various methods.
Categories : PHP, PHP Classes, Sockets, CURL
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)
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
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
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
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL