Skip to main content

Posts

Showing posts with the label Overloading

Overloading in PHP

PHP's interpretation of "overloading" is different than most object oriented languages. Overloading traditionally provides the ability to have multiple methods with the same name but different quantities and types of arguments. In PHP it's achieved through magic methods. Remember : 1) All overloading methods must be defined as public. 2) None of the arguments of these magic methods can be passed by reference. In PHP we have following two types of overloading and their respective functions. Property Overloading : Property overloading is achieved through __get(), __set(), __isset() and __unset() funtions. Property overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods should not be declared static. <?php require_once "DB.php"; class Persistable {        private $data = array();     private $table = "users";        public function __cons...