|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
_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 | |
|
|