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