{"id":70025,"date":"2021-08-23T19:30:45","date_gmt":"2021-08-23T23:30:45","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/oop-concepts-in-php-5-in-brief-16\/"},"modified":"2021-08-23T19:30:45","modified_gmt":"2021-08-23T23:30:45","slug":"oop-concepts-in-php-5-in-brief-16","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=70025","title":{"rendered":"OOP concepts in PHP 5 in brief #16"},"content":{"rendered":"<p><b>OOP concepts in PHP 5 in short<\/b> Why this short &#8211; note? if you are familiar with OOD and any OOP language such as Java\/C++, this short note will give you enough information to start with PHP 5 OOP <b>Class<\/b><\/p>\n<ul>\n<li>Class definition starts with the keyword class, followed by a class name (non reserved word), followed by a pair of curly braces. The curly braces contain the definition of the classes members and methods<\/li>\n<li>You can create objects based on the classes. $obj = new className()<\/li>\n<li>You use $obj-&gt;methodName() to access a class method (public). You can use className::classMember to access class members (static): to use :: operator the method does not need to be declared static<\/li>\n<li>Inside a class all class methods have access to $this variable to refer to the calling object (if called from\/using an object)<\/li>\n<li>member declaration: public $var = &#8216;a default value<\/li>\n<li>Default value always is: constant expression<\/li>\n<li><a href=\"http:\/\/ca3.php.net\/manual\/en\/ref.classobj.php\">Class\/Object Functions<\/a><\/li>\n<li>A class can use extends keyword to inherit methods and members of another class<\/li>\n<li>Multiple inheritance is not allowed<\/li>\n<li>To avoid using a long list of includes in the beginning of php files, you can use __autoload() function to do the job for you<\/li>\n<li>When you try to use an undefined class\/interface an __autoload function is automatically called<\/li>\n<li>\n<pre>function __autoload($class_name) {                 \n   require_once $class_name . '.php';               \n}<\/pre>\n<\/li>\n<li>Constructor syntax: void __construct ([ mixed $args [, $&#8230; ]] )<\/li>\n<li>Parents&#8217; constructors are not automatically called from children&#8217;s constructos. use explicit parent::__construct() instead<\/li>\n<li>Destructor syntax: void __destruct ( void )<\/li>\n<li>Destructor is called: 1. all references to the object are removed 2. the object is explicitly destroyed 3. in shutdown sequence<\/li>\n<li>Parents&#8217; destructors are not automatically called from children&#8217;s destructors. use explicit parent::__destruct() instead<\/li>\n<li>Access modifiers for class members: public, protected or private: Public &#8211; accessible from anywhere. Protected &#8211; accessible from inherited and parent classes, within the class. Private &#8211; accessible within the class<\/li>\n<li>No access modifier = public<\/li>\n<li>:: &#8211; scope resolution operator &#8211; allows access to static, constant, and overridden members or methods of a class<\/li>\n<li>Abstract classes: Introduced in PHP 5. You are not allowed to reate an instance of an abstract class.<\/li>\n<li>Even if a class contains one abstract method, the class must bedeclared abstract<\/li>\n<li>Abstract classes are just about signatures, they cannot define the implementation<\/li>\n<li>A class inheriting from an abstract class, must have to implement all abstract methods. The abstract methods must be defined with the same\/(less restricted) visibility<\/li>\n<li>Interface: Just the method signatures. No method implementation inside interfaces<\/li>\n<li>All interface methods must be public<\/li>\n<li>Classes implementing interfaces must implement all methods. Classes use implements keyword to implement an interface<\/li>\n<li>A class can not implement two interfaces having same class names<\/li>\n<li>Interfaces can be extended using extends keyword<\/li>\n<li>Interfaces can also have constants<\/li>\n<li>Overloading: Overloading in PHP = dynamically &#8220;create&#8221; members and methods<\/li>\n<li>overloading methods: invoked when interacting with non-declared\/invisible members or methods<\/li>\n<li>All overloading methods must be defined as public<\/li>\n<li>In PHP, overloading is done through magic methods<\/li>\n<li>The arguments of the magic methods can not be &#8216;passed by reference&#8217;<\/li>\n<li>Member overloading methods: void __set ( string $name , mixed $value ), mixed __get ( string $name ), bool __isset ( string $name ), void __unset ( string $name )<\/li>\n<li>Method overloading: mixed __call ( string $name , array $arguments ), mixed __callStatic ( string $name , array $arguments )<\/li>\n<li>Object Iteration: Inside the class\n<pre>foreach($this as $key =&gt; $value) {                  \n   print \"$key =&gt; $valuen\";              \n}<\/pre>\n<\/li>\n<li>Object Iteration: Outside class:\n<pre>$class = new MyClass();               \nforeach ($class as $key =&gt; $value) {                 \n   print \"$key =&gt; $valuen\";\n}<\/pre>\n<\/li>\n<li>Patterns: Factory Pattern: allows the instantiation of objects at runtime<\/li>\n<li>Patterns: Singleton: Helps in situations where only a single instance of a class is required that will be used by many other objects<\/li>\n<li>Magic methods: have special meaning. __construct, __destruct (see Constructors and Destructors), __call, __callStatic, __get, __set, __isset, __unset, __sleep, __wakeup, __toString, __set_state and __clone<\/li>\n<li>serialize() &#8211; applies to __sleep(). unserialize() applies to __wakeup()<\/li>\n<li>final keyword: final members can not be overriden, final classes can not be extended<\/li>\n<li>$copy_of_object = clone $object; : will create a clone of $object. Unless a __clone method defined, a shadow is created. __clone() method can define how the cloning will be done<\/li>\n<li>Objects Comparison: == : two object instances are equal if they have the same attributes and values, and are instances of the same class.<\/li>\n<li>Objects Comparison: === : Object variables are identical if and only if they refer to the same instance of the same class<\/li>\n<li>Reflection APIs: to reverse-engineer classes, interfaces, functions and methods, extensions<\/li>\n<li>Reflection APIs: Offer ways to retrieve doc comments for functions, classes and methods<\/li>\n<li>Type Hinting: Functions can enforce parameters to be objects:<\/li>\n<li>Late Static Bindings: to refer the called class in a context of static inheritance.<\/li>\n<\/ul>\n<p>From: http:\/\/sitestree.com\/?p=5105<br \/> Categories:16<br \/>Tags:<br \/> Post Data:2011-07-30 15:39:51<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>OOP concepts in PHP 5 in short Why this short &#8211; note? if you are familiar with OOD and any OOP language such as Java\/C++, this short note will give you enough information to start with PHP 5 OOP Class Class definition starts with the keyword class, followed by a class name (non reserved word), &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=70025\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-70025","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":16206,"url":"http:\/\/bangla.sitestree.com\/?p=16206","url_meta":{"origin":70025,"position":0},"title":"OOP concepts in PHP 5 in brief","author":"Sayed","date":"September 21, 2019","format":false,"excerpt":"OOP concepts in PHP 5 in brief OOP concepts in PHP 5 in brief OOP concepts in PHP 5 in short Why this short\u200a\u2014\u200anote? if you are familiar with OOD and any OOP language such as Java\/C++, this short note will give you enough information to start with PHP 5\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65844,"url":"http:\/\/bangla.sitestree.com\/?p=65844","url_meta":{"origin":70025,"position":1},"title":"Java : SCJP: Important Resources #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"How to use generics to avoid runtime errors. More Generics Class casting in Java: How to avoid runtime exception - ClassCastException: overloading, overriding, variable and method hiding Java HotSpot virtual machine What Java Technology can do? Offers from Java Technology Java:Common Problems (and Their Solutions) Benefits of OOP: Modularity, Information-hiding,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65838,"url":"http:\/\/bangla.sitestree.com\/?p=65838","url_meta":{"origin":70025,"position":2},"title":"SCJP: Class Declarations #Java Short Notes #SCJP","author":"Sayed","date":"July 16, 2021","format":false,"excerpt":"class declarations Start with modifiers such as public, private followed by class keyword The class name, with the initial letter capitalized The name of the class's parent (superclass), preceded by the keyword extends (if any). A class can only extend (subclass) one parent. list of interfaces implemented by the class,\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":68580,"url":"http:\/\/bangla.sitestree.com\/?p=68580","url_meta":{"origin":70025,"position":3},"title":"C++ Concepts and Syntax #77","author":"Author-Check- Article-or-Video","date":"August 5, 2021","format":false,"excerpt":"Not really for the beginners. If you had experience working with C++ in the past, then taking a look at this short-note will help to recover your knowledge in C++. Multiple inheritance means that one subclass can have more than one superclass. This enables the subclass to inherit properties of\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75870,"url":"http:\/\/bangla.sitestree.com\/?p=75870","url_meta":{"origin":70025,"position":4},"title":"PHP Topics to Learn","author":"Sayed","date":"August 1, 2023","format":false,"excerpt":"Identifiers https:\/\/docstore.mik.ua\/orelly\/webprog\/php\/ch02_01.htm#:~:text=An%20identifier%20is%20simply%20a,ASCII%200x7F%20and%20ASCII%200xFF. PHP Data Types https:\/\/www.odinschool.com\/learning-hub\/php\/datatypes Type Hinting https:\/\/www.honeybadger.io\/blog\/php-type-hinting\/#:~:text=Type%2Dhinting%20means%20explicitly%20stating,to%20write%20more%20robust%20code. PDO and MySQL https:\/\/www.w3schools.com\/php\/php_mysql_connect.asp PHP OOP https:\/\/www.w3schools.com\/php\/php_oop_what_is.asp abstract classes https:\/\/www.w3schools.com\/php\/php_oop_classes_abstract.asp Abstract vs Interface https:\/\/www.w3schools.com\/php\/php_oop_interfaces.asp#:~:text=PHP%20%2D%20Interfaces%20vs.%20Abstract%20Classes&text=Interfaces%20cannot%20have%20properties%2C%20while,abstract%20keyword%20is%20not%20necessary , methods, interfaces, and inheritance Pillars of OOP The Four pillars of OOPs, abstraction, encapsulation, inheritance, and polymorphism, are integral to understanding and using OOP https:\/\/datatrained.com\/post\/four-pillars-of-oops\/#:~:text=The%20Four%20pillars%20of%20OOPs%2C%20abstraction%2C%20encapsulation%2C%20inheritance%2C,to%20understanding%20and%20using%20OOP. Four\u2026","rel":"","context":"In &quot;PHP&quot;","block_context":{"text":"PHP","link":"http:\/\/bangla.sitestree.com\/?cat=1427"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78414,"url":"http:\/\/bangla.sitestree.com\/?p=78414","url_meta":{"origin":70025,"position":5},"title":"Differences among Functional Diagrams, Activity Diagrams, Sequence Diagrams, and Class Diagrams? Why are these important in OOD and OOP.","author":"Sayed","date":"August 27, 2025","format":false,"excerpt":"Got it \ud83d\udc4d I\u2019ll structure everything into a clear comparison table that\u2019s easy to read and copyright-free for posting on your FB\/blog. \ud83d\udcd8 OOD & OOP Diagrams \u2013 Quick Comparison Diagram TypePurpose \/ FocusStatic or DynamicExample UseFunctional DiagramShows system functions and how data flows between them.Static (overview level)Mapping out major\u2026","rel":"","context":"In &quot;Enterprise Architect&quot;","block_context":{"text":"Enterprise Architect","link":"http:\/\/bangla.sitestree.com\/?cat=98"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/08\/image-22.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/08\/image-22.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/08\/image-22.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/08\/image-22.png?resize=700%2C400 2x"},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=70025"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/70025\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=70025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=70025"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=70025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}