// API callback
related_results_labels_thumbs({"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$blogger":"http://schemas.google.com/blogger/2008","xmlns$georss":"http://www.georss.org/georss","xmlns$gd":"http://schemas.google.com/g/2005","xmlns$thr":"http://purl.org/syndication/thread/1.0","id":{"$t":"tag:blogger.com,1999:blog-4095748245355156272"},"updated":{"$t":"2023-12-23T10:10:36.395+05:30"},"category":[{"term":"Howto"},{"term":"Facebook Tips"},{"term":"Facebook Tricks"},{"term":"Blogger Tricks"},{"term":"Best  Tricks"},{"term":"Make Money"},{"term":"Net tips"},{"term":"MYSQL"},{"term":"PHP"},{"term":"Pc Tricks"},{"term":"facebook"},{"term":"free"},{"term":"google"},{"term":"AI"},{"term":"Android"},{"term":"Artificial Intelligence"},{"term":"Best  Tips"},{"term":"ChatGPT"},{"term":"Facebook Timeline"},{"term":"Wechat"},{"term":"recharge"},{"term":"Bard"},{"term":"Blogger Widgets"},{"term":"Chatbot"},{"term":"Free Antivirus n key"},{"term":"OpenAI"},{"term":"Orkut tips"},{"term":"Windows Tricks"},{"term":"computer"},{"term":"internet"},{"term":"tricks"},{"term":"whatsapp"},{"term":"windows"},{"term":"CEO"},{"term":"DATABASE"},{"term":"Earn Tricks"},{"term":"Earn money online"},{"term":"FB Status Updater"},{"term":"Free Call"},{"term":"Mobile Tips"},{"term":"NEWS"},{"term":"Net Funny Tricks"},{"term":"PC Tips"},{"term":"SEO Tips"},{"term":"Safe On Facebook"},{"term":"Sundar Pichai"},{"term":"blog"},{"term":"boot"},{"term":"format"},{"term":"microsoft"},{"term":"youtube"},{"term":"4GSpeed"},{"term":"Abstraction"},{"term":"Alphabet"},{"term":"Apache"},{"term":"Article"},{"term":"Atta Pol"},{"term":"Cash"},{"term":"Content"},{"term":"Encapsulation"},{"term":"Extra income"},{"term":"Flexible work"},{"term":"Free Sms to World"},{"term":"Freelancing"},{"term":"Funny Java Tricks"},{"term":"Gift cards"},{"term":"Hosting"},{"term":"Inheritance"},{"term":"Instagram"},{"term":"James Webb Space Telescope"},{"term":"Java Tricks"},{"term":"LG"},{"term":"Launch"},{"term":"Learn PHP"},{"term":"MVC"},{"term":"MariaDB"},{"term":"Market value"},{"term":"Maximize earning potential"},{"term":"Mobile app"},{"term":"Mobile as a Webcam"},{"term":"NASA"},{"term":"Neal Mohan"},{"term":"OOP"},{"term":"Object-Oriented Programming"},{"term":"Online jobs"},{"term":"Orkut Ha(k"},{"term":"PHP applications"},{"term":"PHP programming"},{"term":"PHP scripts"},{"term":"PayPal"},{"term":"Points"},{"term":"Polymorphism"},{"term":"Post"},{"term":"Remote employees"},{"term":"Remote jobs"},{"term":"Remote work"},{"term":"Remote work culture"},{"term":"Rewards"},{"term":"Search engines"},{"term":"Share price"},{"term":"Spare time"},{"term":"Step-by-step guide"},{"term":"Surveys"},{"term":"Susan Wojcicki"},{"term":"Tasks"},{"term":"Telecommuting"},{"term":"Top Ten Antivirus 2012"},{"term":"Trading"},{"term":"Videos"},{"term":"Virtual work"},{"term":"Web Traffic"},{"term":"Website"},{"term":"Work from home"},{"term":"Wrong answer"},{"term":"XAMPP"},{"term":"bluestacks"},{"term":"bootable pendrive"},{"term":"computer setup"},{"term":"control structures"},{"term":"data types"},{"term":"database connectivity"},{"term":"dynamic content"},{"term":"email"},{"term":"file handling"},{"term":"functions"},{"term":"gadgets"},{"term":"highspeed"},{"term":"hotspot"},{"term":"iOS"},{"term":"installation process"},{"term":"leptop"},{"term":"mobile"},{"term":"navbar"},{"term":"operators"},{"term":"programming"},{"term":"scripting language"},{"term":"software bundle"},{"term":"tool"},{"term":"variables"},{"term":"web applications"},{"term":"web development"},{"term":"web server"},{"term":"wifi"}],"title":{"type":"text","$t":"Get Tricks - All Type of Tricks"},"subtitle":{"type":"html","$t":"The site gives knowledge and tricks about social sites, computer tricks, the Internet and earning money online. All Information and tips are in One Place."},"link":[{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https:\/\/www.gettrickz.com\/feeds\/posts\/default"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/4095748245355156272\/posts\/default\/-\/Encapsulation?alt=json-in-script\u0026max-results=5"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.gettrickz.com\/search\/label\/Encapsulation"},{"rel":"hub","href":"http://pubsubhubbub.appspot.com/"}],"author":[{"name":{"$t":"Juber Khan Baloch"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03500557746501068520"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"generator":{"version":"7.00","uri":"http://www.blogger.com","$t":"Blogger"},"openSearch$totalResults":{"$t":"1"},"openSearch$startIndex":{"$t":"1"},"openSearch$itemsPerPage":{"$t":"5"},"entry":[{"id":{"$t":"tag:blogger.com,1999:blog-4095748245355156272.post-1436035524094031151"},"published":{"$t":"2023-02-17T13:28:00.010+05:30"},"updated":{"$t":"2023-02-25T00:14:53.502+05:30"},"category":[{"scheme":"http://www.blogger.com/atom/ns#","term":"Abstraction"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Encapsulation"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Howto"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Inheritance"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Learn PHP"},{"scheme":"http://www.blogger.com/atom/ns#","term":"MYSQL"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Object-Oriented Programming"},{"scheme":"http://www.blogger.com/atom/ns#","term":"OOP"},{"scheme":"http://www.blogger.com/atom/ns#","term":"PHP"},{"scheme":"http://www.blogger.com/atom/ns#","term":"Polymorphism"}],"title":{"type":"text","$t":" Start Learn PHP\/MYSQL : How to Do Object Oriented Programming(OOP) in PHP( Easy Explained )"},"content":{"type":"html","$t":"\u003Cdiv class=\"separator\" style=\"clear: both;\"\u003E\u003Cdiv class=\"separator\" style=\"clear: both; text-align: center;\"\u003E\u003Ca href=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjbDL56QCWVnfsLzlYPHiit0EwPFYUem83KHaGr_1B9TRWU_AQqpJLUNVAuvz1twgJfzJ_4vYxMsPX7C8sgqNq3SY-_E79jGkDZIFkJnwox5oJwwzKp9B5zWIbyTwuCzx7fvL2YSMMUG23cCAhFWRT4HjXEYmGcAL9x_jJSFuAsh3Y-7hq09CCb1wi02w\/s1024\/Object-Oriented-Programming-in-PHP.jpg\" style=\"clear: left; float: left; margin-bottom: 1em; margin-right: 1em;\"\u003E\u003Cimg border=\"0\" data-original-height=\"687\" data-original-width=\"1024\" height=\"215\" src=\"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjbDL56QCWVnfsLzlYPHiit0EwPFYUem83KHaGr_1B9TRWU_AQqpJLUNVAuvz1twgJfzJ_4vYxMsPX7C8sgqNq3SY-_E79jGkDZIFkJnwox5oJwwzKp9B5zWIbyTwuCzx7fvL2YSMMUG23cCAhFWRT4HjXEYmGcAL9x_jJSFuAsh3Y-7hq09CCb1wi02w\/s320\/Object-Oriented-Programming-in-PHP.jpg\" width=\"320\" \/\u003E\u003C\/a\u003E\u003C\/div\u003E\u003Cp\u003EObject-oriented programming(OOP) is a popular programming model used in present time software development. With OOP, programmers can organize code into reusable, modular components, which makes software development more efficient and easier to maintain. PHP, one of the most popular server side scripting languages,supports OOP concepts and provides developers with powerful tools to create robust and scalable applications.\u003C\/p\u003E\u003Cp\u003EIn this article we will take closer look at oops in PHP and explore benefits it offers to developers.We will also discuss essential OOP concepts and how to use them in PHP programming.\u003C\/p\u003E\n\u003Ch3\u003EWhat is Object-Oriented Programming.(OOP)?\u003C\/h3\u003E\n\u003Cp\u003EObject-Oriented Programming is a programming model that focuses on creating software components that can be reused and combined to create complex\/big applications.OOP is built around the concept of objects which represent real world entities or concepts. An object is a self contained unit that has properties and methods that define its behaviour.\u003C\/p\u003E\n\u003Ch3\u003EPHP and OOP:\u003C\/h3\u003E\n\u003Cp\u003EPHP supports OOP concepts and starting from PHP5 it provides robust support for OOP programming. OOP in PHP enables developers to create complex applications by breaking them down into smaller, reusable components. OOP in PHP allows developers to write more organized and maintainable code which is easier to debug and extend.\u003C\/p\u003E\n\u003Cp\u003EObject-Oriented Programming(OOP) in PHP has a large number of methods and keywords that are used to create classes,objects \u0026 methods.Here are some of most commonly used Object-Oriented Programming methods and keywords in PHP programming:\u003C\/p\u003E\n  \u003Col\u003E\u003Ch4\u003E\u003Cli\u003EMethods:\u003C\/li\u003E\u003C\/h4\u003E\u003C\/ol\u003E\u003Cul\u003E\u003Cli\u003E\u003Cb\u003E__construct()\u003C\/b\u003E:a special method that is automatically called when an object is instantiate.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003E__destruct()\u003C\/b\u003E:a special method that is automatically called when an object is destroy.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003E__get()\u003C\/b\u003E: a method that is called when an inaccessible property is accessed.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003E__set()\u003C\/b\u003E: a method that is called when an inaccessible property is set.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003E__call()\u003C\/b\u003E: a method that is called when a not accessible method is called.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Estatic\u003C\/b\u003E: a keyword used to define static methods and properties.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Efinal\u003C\/b\u003E: a keyword used to stop a class from being sub classed or a method from being overridden.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eabstract\u003C\/b\u003E: a keyword used to define abstract classes \u0026 methods.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Einterface\u003C\/b\u003E: a keyword used to define interfaces.\u003C\/li\u003E\u003C\/ul\u003E\u003Col start=\"2\"\u003E\u003Ch4\u003E\u003Cli\u003EKeywords:\u003C\/li\u003E\u003C\/h4\u003E\u003C\/ol\u003E\u003Cul\u003E\u003Cli\u003E\u003Cb\u003Eclass\u003C\/b\u003E:a keyword used to define a class.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Enew\u003C\/b\u003E:a keyword used to create an object instance of a class.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eextends \u003C\/b\u003E: a keyword used to define inheritance between classes.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Epublic \u003C\/b\u003E:a keyword used to declare a property\/method as publicly accessible.\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eprivate \u003C\/b\u003E-a keyword used to declare a property or method as accessible only within the class that defines it\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eprotected \u003C\/b\u003E-a keyword used to declare a property or method as accessible only within the class that defines it and its subclasses\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Ethis \u003C\/b\u003E-a keyword used to refer to the current object instance within a class method\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eself \u003C\/b\u003E- a keyword used to refer to the current class within a class method\u003C\/li\u003E\u003Cli\u003E\u003Cb\u003Eparent \u003C\/b\u003E- a keyword used to refer to the parent class within a class method\u003C\/li\u003E\u003C\/ul\u003E\u003Cp\u003EThese are just a few of the many methods \u0026 keywords available in OOP in PHP. By understanding and using these methods and keywords effectively, you can create more powerful and efficient object-oriented code.\u003C\/p\u003E\n\u003Ch3\u003EEssential OOP Concepts:\u003C\/h3\u003E\n\u003Col\u003E\u003Ch4\u003E\u003Cli\u003EClasses and Objects:\u003C\/li\u003E\u003C\/h4\u003E\n  \u003Cp\u003EClasses define the blueprint or structure of an object, while objects are instances of a class. A class is a template that defines the properties and methods of an object, while an object is a concrete realization of a class.\u003C\/p\u003E\n  \u003Cp\u003EIn PHP there are three types of classes and objects: regular classes, abstract classes and interfaces.Let's take a look at each of them and their rules.\u003C\/p\u003E\n  \u003Col\u003E\u003Cli\u003E\u003Cstrong\u003ERegular Classes\u003C\/strong\u003E\nRegular classes are the most common type of class in PHP and they can be instantiated to create objects.These classes can have properties and methods, which can be accessed using object notation.\u003C\/li\u003E\u003C\/ol\u003E\u003Cp\u003ERules:\u003C\/p\u003E\u003Cul\u003E\u003Cli\u003ERegular classes must have a class keyword followed by a name and a set of curly braces.\u003C\/li\u003E\u003Cli\u003EClass names should follow CamelCase naming convention.\u003C\/li\u003E\u003Cli\u003EA class must be instantiated before it can be used to create objects.\u003C\/li\u003E\u003Cli\u003EProperties and methods must have an access modifier, which determines their visibility.The three access modifiers are public, protected and private.\u003C\/li\u003E\u003Cli\u003EA class can inherit from another class using the extends keyword.\u003C\/li\u003E\u003C\/ul\u003E\u003Cp\u003EExample:\u003C\/p\u003E\n  \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \nclass Car {\n    public $make;\n    public $model;\n\n    public function start() {\n        \/\/code to start the car\n    }\n\n    private function checkFuel() {\n        \/\/code to check the level of  fuel \n    }\n}\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Col start=\"2\"\u003E\u003Cli\u003E\u003Cstrong\u003EAbstract Classes\u003C\/strong\u003E\nAbstract classes are similar to regular classes but they cannot be instantiated on their own. Instead, they are meant to be extended by other classes. Abstract classes can have abstract methods, which are methods without implementation.These methods must be implemented by any class that extends the abstract class.\u003C\/li\u003E\u003C\/ol\u003E\u003Cp\u003ERules:\u003C\/p\u003E\u003Cul\u003E\u003Cli\u003EAbstract classes must have an abstract keyword before the class keyword.\u003C\/li\u003E\u003Cli\u003EAn abstract class cannot be instantiated on its own.\u003C\/li\u003E\u003Cli\u003EAbstract classes can have abstract methods which are declared without an implementation.\u003C\/li\u003E\u003Cli\u003EAny class that extends an abstract class must implement all of its abstract methods.\u003C\/li\u003E\u003C\/ul\u003E\u003Cp\u003EExample:\u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \nabstract class Vehicle {\n    public $make;\n    public $model;\n\n    abstract public function start();\n}\n\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Col start=\"3\"\u003E\u003Cli\u003E\u003Cstrong\u003EInterfaces\u003C\/strong\u003E\nInterfaces are alike to abstract classes but they can only have method signatures and constants.Any class that implements an interface must implement all of its methods. Interfaces are used to define a set of methods that must be implemented by any class that wants to use them.\u003C\/li\u003E\u003C\/ol\u003E\u003Cp\u003ERules: \u003C\/p\u003E\u003Cul\u003E\u003Cli\u003E Interfaces must have an interface keyword followed by a name and a set of curly braces.\u003C\/li\u003E\u003Cli\u003EInterfaces can only have method signatures and constants not properties or method implementations.\u003C\/li\u003E\u003Cli\u003EAny class that implements an interface must implement all of its methods.\u003C\/li\u003E\u003C\/ul\u003E\u003Cp\u003E Example:\u003C\/p\u003E\n \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \ninterface Printable {\n    public function print();\n}\n\n\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003EIn summary regular classes, abstract classes and interfaces all have different rules and use cases in PHP. Regular classes are the most common and can be instantiated to create objects while abstract classes and interfaces are used for more specialized cases, such as creating blueprints for other classes or defining a set of methods that must be implemented by other classes.\u003C\/p\u003E\n  \n \u003Cp\u003EFull Example of classes and objects in PHP.Imagine we are building a simple website for a library, and we want to create a class for the books that will be displayed on the site.We can create a Book class that will have properties for the title, author, and number of pages.\u003C\/p\u003E\n  \n \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n class Book {  \n   public $title;  \n   public $author;  \n   public $pages;  \n }  \n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \n  \u003Cp\u003EWe can then create object of the BOOK class and set its properties... \u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n$book1 = new Book();\n$book1-\u0026gt;title = \"To Kill a Mockingbirds\";\n$book1-\u0026gt;author = \"Harry Lee\";\n$book1-\u0026gt;pages = 281;\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003EWe can also create additional objects of the BOOK class and set their properties...\u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n  \n \u0026lt;?php  \n \n$book2 = new Book();\n$book2-\u0026gt;title = \"The Great Gat sby\";\n$book2-\u0026gt;author = \"F. Scott Fitz gerald\";\n$book2-\u0026gt;pages = 180;\n\n$book3 = new Book();\n$book3-\u0026gt;title = \"Pride and Pre judice\";\n$book3-\u0026gt;author = \"Jane Aus\";\n$book3-\u0026gt;pages = 279;\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n\n  \u003Cp\u003EWe can then display the properties of each object using the echo statement.\u003C\/p\u003E\n  \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \necho $book1-\u0026gt;title; \/\/ Output: To Kill a Mockingbird\necho $book2-\u0026gt;author; \/\/ Output: F. Scott Fitzgerald\necho $book3-\u0026gt;pages; \/\/ Output: 279\n\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003EWe can also define methods with in the Book class to perform various tasks such as calculating the number of pages read per hour.\u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \nclass Book {\n    public $title;\n    public $author;\n    public $pages;\n\n    public function readPagesPerHour($hours) {\n        return $this-\u0026gt;pages \/ $hours;\n    }\n}\n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003EWe can then call method on an object of the BOOK class...\u003C\/p\u003E\n  \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n$book1 = new Book();\n$book1-\u0026gt;title = \"To Kill a Mockingbird\";\n$book1-\u0026gt;author = \"Harper Lee\";\n$book1-\u0026gt;pages = 281;\n\necho $book1-\u0026gt;readPagesPerHour(2); \/\/ Output: 140.5\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003EAs you can see classes and objects in PHP provide a powerful way to encapsulate data and logic in reusable components. By defining a class, we can create multiple instances of that class (i.e.objects) with their own unique properties and methods.This makes our code more modular and easier to maintain as well as more efficient and scalable.\u003C\/p\u003E\n  \n  \u003Ch4\u003E\u003Cli\u003EEncapsulation:\u003C\/li\u003E\u003C\/h4\u003E\u003Ch4\u003E\n    \u003Cp\u003E\n     Encapsulation is a mechanism that hides the internal details of an object and exposes only the necessary information. It ensures that the data inside an object is not accessible from outside the object. It is an important concept in Object-Oriented Programming(OOP) that allows you to hide the implementation details of a class from the outside world.This helps to prevent accidental modification of class properties and methods and ensures that they are only accessed and modified in a controlled way. In PHP,encapsulation can be achieved using access modifiers such as public, private and protected.\u003C\/p\u003E\n    \u003Col\u003E\u003Ch5\u003E\u003Cli\u003EPublic:\u003C\/li\u003E\u003C\/h5\u003E\u003C\/ol\u003E\u003Cp\u003E\nPublic properties and methods are accessible from anywhere in the code both inside and outside of the class. This means that they can be accessed by objects, functions, and other classes.\u003C\/p\u003E\n      \u003Col start=\"2\"\u003E\u003Ch5\u003E\u003Cli\u003EPrivate : \u003C\/li\u003E\u003C\/h5\u003E\u003C\/ol\u003E\u003Cp\u003E\nPrivate properties and methods are only accessible from with in the class. They cannot be accessed by objects functions or other classes outside of the class. This means that the value of a private property can only be set or retrieved by methods within the same class.\u003C\/p\u003E\n    \u003Col start=\"3\"\u003E\u003Ch5\u003E\u003Cli\u003EProtected : \u003C\/li\u003E\u003C\/h5\u003E\u003C\/ol\u003E\u003Cp\u003E\nProtected properties and methods are only accessible from within the class and its subclasses. This means that they cannot be accessed by objects or functions outside of the class but they can be accessed by subclasses that inherit from the class.\u003C\/p\u003E\n    \n    \u003Cp\u003EHere example of Encapsulation in PHP:\u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n class BankAccount {  \n   private $balance;  \n   \n   public function deposit($amount) {  \n     $this-\u0026gt;balance += $amount;  \n   }  \n   \n   public function withdraw($amount) {  \n     if ($amount \u0026lt;= $this-\u0026gt;balance) {  \n       $this-\u0026gt;balance -= $amount;  \n     } else {  \n       echo \"Insufficient funds\";  \n     }  \n   }  \n   \n   public function getBalance() {  \n     return $this-\u0026gt;balance;  \n   }  \n }  \n\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example, we define a Bank Account class with a private property $balance and three methods: deposit(), withdraw()and \u003Ccode\u003EgetBalance(). The deposit() method allows a user to add money to their account, while the withdraw() method allows them to remove money from their account. The \u003Ccode\u003EgetBalance()\u003C\/code\u003E method allows them to check their current account balance.\u003C\/p\u003E\n    \u003Cp\u003ENote that the $balance property is marked as private, which means that it can only be accessed within the class itself. This ensures that the balance can only be modified by the deposit() and \u003Ccode\u003Ewithdraw() methods, and cannot be accessed or modified directly from outside the class. This helps to prevent accidental modification of the balance and ensures that it is only accessed and modified in a controlled way.\u003C\/p\u003E\n    \u003Cp\u003EHere an example of how to use the Bank Account class:\u003C\/p\u003E\n    \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n  \n \u0026lt;?php  \n$account = new BankAccount();  \n $account-\u0026gt;deposit(1000);  \n $account-\u0026gt;withdraw(500);  \n echo \"Acc Balance: \" . $account-\u0026gt;getBalance();  \n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example we create a new Bank Account object, deposit 1000 into the account, withdraw 500 from the account, and then print the current balance using the getBalance() method. Note that we can only access the balance using the getBalance() method, and cannot modify it directly.\u003C\/p\u003E\n    \u003Cp\u003EBy encapsulating the balance property and only allowing it to be accessed and modified through controlled methods, we can ensure that the account balance is always accurate and that it cannot be accidentally modified or tampered with.\u003C\/p\u003E\n    \n    \u003C\/h4\u003E\u003Ch4\u003E\u003Cli\u003EInheritance:\u003C\/li\u003E\u003C\/h4\u003E\u003Cp\u003EInheritance is a mechanism that enables one class to inherit properties and methods from another class. Inheritance promotes code reuse, and it simplifies the design and maintenance of complex applications.It is a powerful feature in Object-Oriented Programming (OOP) that allows you to create new classes that are based on existing classes, inheriting their properties and methods. In PHP, you can use the extends keyword to create a subclass that inherits from a parent class.\u003C\/p\u003E\n    \u003Cp\u003EHere example of inheritance in PHP:\u003C\/p\u003E\n     \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n  \u003Ccode\u003E \n \u0026lt;?php  \n \n class Animal {  \n     protected $name;  \n   protected $color;  \n   \n   public function __construct($name, $color) {  \n          $this-\u0026gt;name = $name;  \n     $this-\u0026gt;color = $color;   \n  }  \n   \n   public function eat() {  \n               echo  \"{$this-\u0026gt;name}    eating...\";     }  \n }  \n   \n class Dog extends Animal {  \n   public function bark() {  \n     echo  \"{$this-\u0026gt;name}    barking...\";   } \n }  \n\n ?\u0026gt;  \n  \u003C\/code\u003E\n\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003E  In this example we define an Animal class with two protected properties ($name and $color) and a eat() method. We then define a Dog class that extends the Animal class, and adds a bark() method.\n    \u003C\/p\u003E\u003Cp\u003E\nNote that the Dog class uses the extends keyword to inherit from the Animal class.This means that the Dog class will have access to all of the properties and methods of the Animal class, as well as its own bark() method.\u003C\/p\u003E\n    \u003Cp\u003E Here example of how to use the Dog class:\u003C\/p\u003E\n    \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n  \n \u0026lt;?php  \n \n$dog = new Dog('Fido', 'Brown');\n$dog-\u0026gt;eat(); \/\/  Output: Fido eating...\n$dog-\u0026gt;bark(); \/\/  Output: Fido  barking...\n \n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example we create a new DOG object and pass in a name and color to its constructor.We then call its eat() and bark() methods which were inherited from the Animal class and defined in the Dog class respectively.\u003C\/p\u003E\n    \u003Cp\u003EBy using inheritance we can create new classes that are based on existing classes inheriting their properties and methods and adding new functionality. This allows us to write more efficient and reusable code and makes it easier to organize and maintain our programs\u003C\/p\u003E\n    \n  \u003Ch4\u003E\u003Cli\u003EPolymorphism: \u003C\/li\u003E\u003C\/h4\u003E\n    \u003Cp\u003EPolymorphism is the ability of an object to take on different forms or behaviors. In PHP, polymorphism is achieved through method overriding and method overloading.It is an important concept in Object-Oriented Programming (OOP) that allows objects of different classes to be treated as if they were the same type. This is achieved by using inheritance and method overriding, which allows a subclass to provide its own implementation of a method that is already defined in its parent class. In PHP, polymorphism can be achieved using the extends keyword and the override keyword.\u003C\/p\u003E\n    \u003Cp\u003EHere example of polymorphism in PHP:\u003C\/p\u003E\n    \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n class Shape\n {  \n   public function getArea() \n{  \n     return 0;  \n   }  \n }  \n   \n class Circle extends  Shape\n {  \n   private $radius;  \n   \n   public function __construct($radius) \n{  \n     $this-\u0026gt;radius = $radius;  \n }  \n   \n   public function getArea()\n {  \n     return 3.14 * $this-\u0026gt;radius * $this-\u0026gt;radius;  \n               }  \n }  \n   \n class Square extends Shape {  \n   private $length;  \n   \n   public function __construct($length){  \n     $this-\u0026gt;length = $length;  \n                           }  \n   \n   public function getArea() \n{  \n     return $this-\u0026gt;length * $this-\u0026gt;length;     }  \n }  \n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example we define a Shape class with a getArea() method that returns 0.We then define two subclasses: Circle and Square, both of which extend the Shape class and provide their own implementation of the getArea() method. \u003C\/p\u003E \u003Cp\u003E\n\nNote that the getArea() method is defined in the Shape class and overridden in the Circle and Square classes. This allows objects of the Circle and Square classes to be treated as if they were objects of the Shape class because they share the same method signature.\n \u003C\/p\u003E \u003Cp\u003E\nHere example of how to use the Shape, Circle, and Square classes: \u003C\/p\u003E\n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n  $shapes = array(  \n   new Circle(5),  \n   new Square(4),  \n   new Circle(3)  \n );  \n   \n foreach ($shapes as $shape){  \n   echo \"Area: \" . $shape-\u0026gt;getArea() . \"\u0026lt;br\u0026gt;\";  \n }  \n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example we create an array of Shape objects that contains two Circle objects and one Square object. We then iterate over the array and call the getArea() method on each object which will call the appropriate implementation of the method in each subclass.\u003C\/p\u003E\n    \u003Cp\u003EBy using polymorphism we can write more flexible and extensible code that can be easily adapted to different situations. This allows us to write code that is more maintainable, reusable and efficient and makes it easier to add new functionality to our programs.\u003C\/p\u003E\n    \n    \u003Ch4\u003E\u003Cli\u003EAbstraction: \u003C\/li\u003E\u003C\/h4\u003E\n    \u003Cp\u003EAbstraction is a mechanism that allows developers to create generalized models of realworld entities \/ concepts. It helps to reduce complexity and increase the reusability of code.It is an important concept in Object-Oriented Programming (OOP) that allows us to hide the implementation details of a class from its users, while still providing a clear and concise interface for interacting with that class. In PHP we can achieve abstraction by using abstract classes and abstract methods.\u003C\/p\u003E\n    \u003Cp\u003EHere example of abstraction in PHP:\u003C\/p\u003E\n     \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n abstract class  Shape {  \n   protected $color;  \n   \n   public function __construct($color)   {  \n     $this-\u0026gt;color = $color;  \n   }  \n   \n   public function getColor() {  \n     return  $this-\u0026gt;color;  \n   }  \n   abstract public function getArea();  \n }  \n \n class Circle extends Shape {  \n   private $radius;  \n   public function __construct($color, $radius)\n {  \n     parent::__construct($color);  \n     $this-\u0026gt;radius = $radius;  \n }  \n   public function getArea() {  \n     return 3.14 * $this-\u0026gt;radius * $this-\u0026gt;radius; \n}  \n }  \n class Square extends Shape {  \n   private   $length;  \n   public function __construct($color, $length) {  \n     parent::__construct($color);  \n     $this-\u0026gt;length = $length;  \n   }     \n   public function getArea() {  \n     return $this-\u0026gt;length * $this-\u0026gt;length;  \n   }  \n }  \n   \n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n    \u003Cp\u003EIn this example we define a Shape class with a getArea() method that returns 0. We then define two subclasses: Circle and Square, both of which extend the Shape class and provide their own implementation of the getArea() method.\n    \u003C\/p\u003E\u003Cp\u003E\nNote that the getArea() method is defined in the Shape class and overridden in the Circle and Square classes. This allows objects of the Circle and Square classes to be treated as if they were objects of the Shape class because they share the same method signature.\n    \u003C\/p\u003E\u003Cp\u003E\nHere example of how to use the Shape, Circle and Square classes:\n    \u003C\/p\u003E\n    \n   \n \u003Cdiv class =\"clsviewer \" \u003E\n  \u003Cdiv class =\"clsheader \"\u003E\n             \u003Ci class =\" languagecls \"\u003E  PHP \u003C\/i\u003E \n  \u003C\/div\u003E\n  \u003C pre class=\"ccontentclss \" \u003E\n\u003Ccode\u003E \n \n \u0026lt;?php  \n \n$shapes = array(\n    new Circle(5),\n    new Square(4),\n    new Circle(3)\n);\nforeach ($shapes as $shape) {\n    echo \"Area : \" . $shape-\u0026gt;getArea() . \"\u003Cbr\u003E\";\n}\n\n ?\u0026gt;  \n  \u003C\/code\u003E\u003C\/pre\u003E\n\u003C\/div\u003E\n  \u003Cp\u003E In this example We create an array of Shape objects that contains two Circle objects and one Square object.We then iterate over the array and call the getArea() method on each object which will call the appropriate implementation of the method in each subclass.\n    \u003C\/p\u003E\u003Cp\u003E\nBy using polymorphism we can write more flexible and extensible code that can be easily adapted to different situations.This allows us to write code that is more maintainable, reusable and efficient and makes it easier to add new functionality to our programs. \u003C\/p\u003E\u003C\/ol\u003E\n\n\u003Ch4\u003EBenefits of OOP in PHP:\u003C\/h4\u003E\n\u003Col\u003E\u003Cli\u003E\u003Cp\u003EReusability :OOP in PHP enables developers to write reusable code, which reduces development time and increases efficiency.\u003C\/p\u003E\u003C\/li\u003E\u003Cli\u003E\u003Cp\u003E  Modularity: OOP in PHP allows developers to break down complex applications into smaller manageable components.This improves the organization of code and makes it easier to maintain and debug. \u003C\/p\u003E\u003C\/li\u003E\u003Cli\u003E\u003Cp\u003E  Extensibility: OOP in PHP promotes the use of inheritance and polymorphism which allows developers to extend the functionality of existing code without modifying the original code.\u003C\/p\u003E\u003C\/li\u003E \u003Cli\u003E\u003Cp\u003ESecurity: O O P in PHP enables developers to implement secure coding practices such as encapsulation and data hiding which helps to protect sensitive data from unauthorized access.\u003C\/p\u003E\u003C\/li\u003E\u003C\/ol\u003E\n\n\u003Cp\u003EOOP in PHP is a powerful programming paradigm that enables developers to create scalable, efficient and maintainable applications. The essential OOP concepts in PHP including classes and objects, encapsulation, inheritance, polymorphism and abstraction, make it possible to create reusable, modular and secure code. By understanding the benefits of OOP in PHP developers can write better quality code that is easier to maintain and extend.\u003C\/p\u003E"},"link":[{"rel":"edit","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/4095748245355156272\/posts\/default\/1436035524094031151"},{"rel":"self","type":"application/atom+xml","href":"https:\/\/www.blogger.com\/feeds\/4095748245355156272\/posts\/default\/1436035524094031151"},{"rel":"alternate","type":"text/html","href":"https:\/\/www.gettrickz.com\/2023\/02\/object-oriented-programming-in-php.html","title":" Start Learn PHP\/MYSQL : How to Do Object Oriented Programming(OOP) in PHP( Easy Explained )"}],"author":[{"name":{"$t":"Juber Khan Baloch"},"uri":{"$t":"http:\/\/www.blogger.com\/profile\/03500557746501068520"},"email":{"$t":"noreply@blogger.com"},"gd$image":{"rel":"http://schemas.google.com/g/2005#thumbnail","width":"16","height":"16","src":"https:\/\/img1.blogblog.com\/img\/b16-rounded.gif"}}],"media$thumbnail":{"xmlns$media":"http://search.yahoo.com/mrss/","url":"https:\/\/blogger.googleusercontent.com\/img\/b\/R29vZ2xl\/AVvXsEjbDL56QCWVnfsLzlYPHiit0EwPFYUem83KHaGr_1B9TRWU_AQqpJLUNVAuvz1twgJfzJ_4vYxMsPX7C8sgqNq3SY-_E79jGkDZIFkJnwox5oJwwzKp9B5zWIbyTwuCzx7fvL2YSMMUG23cCAhFWRT4HjXEYmGcAL9x_jJSFuAsh3Y-7hq09CCb1wi02w\/s72-c\/Object-Oriented-Programming-in-PHP.jpg","height":"72","width":"72"}}]}});