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
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
Mobile Dev World

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 : 13795
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.



Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
ECHO-PHP Class Real Time Transaction Processor v1.4.4 for Credit Cards and Checks / ACH
Categories : PHP Classes, Cybercash, Classes and Objects, Ecommerce, PHP
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network, Email, PHP, PHP Classes
Export Excel Dynamically to Csv then to mysql
Categories : PHP Classes, Excel, PHP
base64 with encryption - encode and decode sessions
Categories : PHP, PHP Classes, Encryption, Sessions
PDF class - This is a useful class to make a pdf file with php functions.
Categories : PHP, PDF, PHP Classes
ElfReader: An ELF (Executable and Linking Format) header information in PHP. Shows how to use the UNPACK function to read data.
Categories : PHP, Linux, PHP Classes
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
PHP Composer - This class is meant to render images of the musical score of ring tones notes used in cellular phones, defined in the RTTL format.
Categories : PHP, PHP Classes, Misc
MS Word Mail Merge Automation (COM)
Categories : PHP, PHP Classes, COM
Very minimal templating engine
Categories : PHP, PHP Classes, Templates
XPertMailer - Sends TRUE Mails
Categories : PHP, Mail, SMTP, PHP Classes