{"id":16206,"date":"2019-09-21T08:52:25","date_gmt":"2019-09-21T12:52:25","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/oop-concepts-in-php-5-in-brief\/"},"modified":"2019-09-21T08:52:25","modified_gmt":"2019-09-21T12:52:25","slug":"oop-concepts-in-php-5-in-brief","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=16206","title":{"rendered":"OOP concepts in PHP 5 in brief"},"content":{"rendered":"<h3>OOP concepts in PHP 5 in brief<\/h3>\n<p> <img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/800\/1%2AUQKkJhqTgaCVWVQW2BbNXQ.jpeg?w=750&#038;ssl=1\" alt=\"1*UQKkJhqTgaCVWVQW2BbNXQ.jpeg\" \/><\/p>\n<p>OOP concepts in PHP 5 in brief<\/p>\n<p><strong>OOP concepts in PHP 5 in short<\/strong><\/p>\n<p>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 OOP <strong>Class<\/strong><\/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 = \u2018a 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>function __autoload($class_name) {<br \/>\nrequire_once $class_name . \u2018.php\u2019;<br \/>\n}<\/li>\n<li>Constructor syntax: void __construct ([ mixed $args [, $\u2026 ]] )<\/li>\n<li>Parents\u2019 constructors are not automatically called from children\u2019s constructor. 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\u2019 destructors are not automatically called from children\u2019s destructors. use explicit parent::__destruct() instead<\/li>\n<li>Access modifiers for class members: public, protected or private: Public\u200a\u2014\u200aaccessible from anywhere. Protected\u200a\u2014\u200aaccessible from inherited and parent classes, within the class. Private\u200a\u2014\u200aaccessible within the class<\/li>\n<li>No access modifier = public<\/li>\n<li>::\u200a\u2014\u200ascope resolution operator\u200a\u2014\u200aallows 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 \u201ccreate\u201d 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 \u2018passed by reference\u2019<\/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<\/li>\n<li>foreach($this as $key =&gt; $value) {<br \/>\nprint \u201c$key =&gt; $valuen\u201d;<br \/>\n}<\/li>\n<\/ul>\n<ul>\n<li>Object Iteration: Outside class:<\/li>\n<li>$class = new MyClass();<br \/>\nforeach ($class as $key =&gt; $value) {<br \/>\nprint \u201c$key =&gt; $valuen\u201d;<br \/>\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()\u200a\u2014\u200aapplies 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<li><\/li>\n<\/ul>\n<p>Sayed Ahmed<\/p>\n<p>Linkedin: <a href=\"https:\/\/ca.linkedin.com\/in\/sayedjustetc\">https:\/\/ca.linkedin.com\/in\/sayedjustetc<\/a><\/p>\n<p>Blog: <a href=\"http:\/\/bangla.salearningschool.com\/\">http:\/\/bangla.saLearningSchool.com<\/a> <a href=\"http:\/\/sitestree.com\">http:\/\/SitesTree.com<\/a>,<br \/>\nOnline and Offline Training: <a href=\"http:\/\/training.SitesTree.com\">http:\/\/training.SitesTree.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 OOP Class Class definition starts &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=16206\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[182],"tags":[],"class_list":["post-16206","post","type-post","status-publish","format-standard","hentry","category---blog","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70025,"url":"http:\/\/bangla.sitestree.com\/?p=70025","url_meta":{"origin":16206,"position":0},"title":"OOP concepts in PHP 5 in brief #16","author":"Author-Check- Article-or-Video","date":"August 23, 2021","format":false,"excerpt":"OOP concepts in PHP 5 in short Why this short - 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\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":16206,"position":1},"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":70053,"url":"http:\/\/bangla.sitestree.com\/?p=70053","url_meta":{"origin":16206,"position":2},"title":"PHP What to Learn? When are you an Expert? #16","author":"Author-Check- Article-or-Video","date":"August 24, 2021","format":false,"excerpt":"Check your PHP KnowledgeDo you know all of the following concepts? If not - why don't you learn? Know all of them and claim yourself to be an expert in PHP. How to go about learning? First know all the concepts. Then go to the details of each topic. Learning\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":16206,"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":23309,"url":"http:\/\/bangla.sitestree.com\/?p=23309","url_meta":{"origin":16206,"position":4},"title":"PHP and OOP #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 29, 2021","format":false,"excerpt":"http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=987 From: http:\/\/sitestree.com\/?p=3937 Categories:Root, By Sayed AhmedTags: Post Data:2016-09-15 14:17:16 Shop Online: https:\/\/www.ShopForSoul.com\/ (Big Data, Cloud, Security, Machine Learning): Courses: http:\/\/Training.SitesTree.com In Bengali: http:\/\/Bangla.SaLearningSchool.com http:\/\/SitesTree.com 8112223 Canada Inc.\/JustEtc: http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) Shop Online: https:\/\/www.ShopForSoul.com\/ Medium: https:\/\/medium.com\/@SayedAhmedCanada","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":22529,"url":"http:\/\/bangla.sitestree.com\/?p=22529","url_meta":{"origin":16206,"position":5},"title":"Resources Checked Recently on PHP, OOP, OOD, Java, Angular, Bootstrap, Design Patterns #Root #By Sayed Ahmed #Misc. Reading","author":"Author-Check- Article-or-Video","date":"March 15, 2021","format":false,"excerpt":"Resources Checked Recently on PHP, OOP, OOD, Java, Angular, Bootstrap, Design Patterns http:\/\/www.fluffycat.com\/PHP-Design-Patterns\/PHP-Job-Interview-Questions\/ http:\/\/php.net\/manual\/en\/language.oop5.object-comparison.php http:\/\/www.programmerinterview.com\/index.php\/design-pattern-questions\/design-pattern-interview-questions-and-answers\/ https:\/\/www.glassdoor.co.in\/Interview\/canada-software-developer-interview-questions-SRCH_IL.0,6_IN3_KO7,25.htm http:\/\/www.tutorialspoint.com\/design_pattern\/decorator_pattern.htm http:\/\/www.fluffycat.com\/PHP-Design-Patterns\/ http:\/\/programmers.stackexchange.com\/questions\/7055\/what-is-the-most-frequently-used-design-pattern http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=893 http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=987 Abstract Factory: https:\/\/sourcemaking.com\/design_patterns\/abstract_factory\/php\/2 Decorator Pattern: http:\/\/www.tutorialspoint.com\/design_pattern\/decorator_pattern.htm Singleton: http:\/\/stackoverflow.com\/questions\/8776788\/best-practice-on-php-singleton-classes http:\/\/stackoverflow.com\/questions\/203336\/creating-the-singleton-design-pattern-in-php5\/203359#203359 https:\/\/ttmm.io\/tech\/making-singletons-safe-in-php\/ Java http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=858 http:\/\/stackoverflow.com\/questions\/9948008\/what-is-sapi-and-when-would-you-use-it Cookie - securing Cookie http:\/\/blog.teamtreehouse.com\/how-to-create-totally-secure-cookies http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1357&title=PHP%20Security%20-%20Guidelines https:\/\/www.quora.com\/What-is-the-difference-between-htmlentities-and-htmlspecialchars-in-PHP http:\/\/stackoverflow.com\/questions\/46483\/htmlentities-vs-htmlspecialchars Prevent CSRF in PHP http:\/\/stackoverflow.com\/questions\/1780687\/preventing-csrf-in-php PHP Security Package:\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":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16206","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\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16206"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16206\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16206"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}