In this HTML tutorial, you will find more than 200 examples. With our online "Try it Yourself" editor, you can edit and test each example yourself! Go to HTML Examples! Place for your advertisement! HTML ExercisesThis HTML tutorial also contains nearly 100 HTML exercises. Test Yourself With ExercisesExercise:Add a "tooltip" to the paragraph below with the text "About W3Schools". <p ="About W3Schools">W3Schools is a web developer's site.</p> Submit Answer » HTML Quiz TestTest your HTML skills with our HTML Quiz! Start HTML Quiz! Place for your advertisement! HTML ReferencesAt W3Schools you will find complete references about HTML elements, attributes, events, color names, entities, character-sets, URL encoding,language codes, HTTP messages, browser support, and more:
Example 1Output: Object Oriented Programming is a software approach added to PHP5, which helps in building the composite application in an easy way. Some of the OOP concepts added into the PHP5 are an abstraction, interface, static method, and static class, etc... In this article, we will learn Encapsulation and it's implementation through a few examples. The wrapping up of data and methods into a single unit (called class) is known as encapsulation. Encapsulation is a protection mechanism for the data members and methods present inside the class. In the encapsulation technique, we are restricting the data members from access to outside world end-user. In PHP, encapsulation utilized to make the code more secure and robust. Using encapsulation, we are hiding the real implementation of data from the user and also does not allow anyone to manipulate data members except by calling the desired operation. ExampleLet' understand this through an example. CheckBalance(10005285637,1**3); ?> Explanation:In this example, all the ATM class data members (variable) are marked with the private modifier. It implies that we can not directly access ATM class data members (property). So, we can't change the class property directly. The only approach to change the class property (data members) is calling a method (function). That’s the reason we have stated all the ATM class methods with a public access modifier. The user can pass the expected arguments to a class method to perform a particular task. Suppose anyone wants to check balance then he needs to access the CheckBalance() method with the required arguments $custid="10005285637" and $atmpin="1**3". This is called Data hiding through Encapsulation. In today’s technical world, maintaining privacy has become one of the demanding needs for the protection of important data. Whenever data modified in one function affects the other functions, it causes a lot of problems in any software. To overcome this problem, object-oriented programming in PHP uses the concept of Encapsulation. So the OOPs concept of Encapsulation in PHP means, enclosing the internal details of the object to protect from external sources. It describes, combining the class, data variables and member functions that work on data together within a single unit to form an object. Otherwise, its the bundling of properties and behavior in a single class unit. Data is not accessed directly, in fact, they are accessed through functions(GET or SET) written inside the class. Attributes are kept private but getter(GET) and setter(SET) methods are kept public for manipulation of these attributes. PHP program for encapsulation: The methods or functions in the following program are update password and check the course name. GFG class defines all the operations related to GFG users.
First name is set to Meena Gender is set to Female0 First name is set to Meena Gender is set to Female1
First name is set to Meena Gender is set to Female4 First name is set to Meena Gender is set to Female1 First name is set to Meena Gender is set to Female6
First name is set to Meena Gender is set to Female8
First name is set to Meena Gender is set to Female0 <?php 4First name is set to Meena Gender is set to Female4 <?php 6
First name is set to Meena Gender is set to Female4 5 8 5First name is set to Meena Gender is set to Female0 // PHP program to implements encapsulation 1
First name is set to Meena Gender is set to Female1
First name is set to Meena Gender is set to Female0 <?php 6
First name is set to Meena Gender is set to Female0 // PHP program to implements encapsulation 1
First name is set to Meena Gender is set to Female1
Output: Function to update password 'geeks54321' for user GFG12 Function to check course name of user GFG06 Note: The data members and class properties are not accessible to the outer end-user. So they cannot change the properties. Program to Access Variables
First name is set to Meena Gender is set to Female00 First name is set to Meena Gender is set to Female1
First name is set to Meena Gender is set to Female04 First name is set to Meena Gender is set to Female1
First name is set to Meena Gender is set to Female10
First name is set to Meena Gender is set to Female12 First name is set to Meena Gender is set to Female13 First name is set to Meena Gender is set to Female14
First name is set to Meena Gender is set to Female21 First name is set to Meena Gender is set to Female00 <?php 6
First name is set to Meena Gender is set to Female13 First name is set to Meena Gender is set to Female26 First name is set to Meena Gender is set to Female00 First name is set to Meena Gender is set to Female1
First name is set to Meena Gender is set to Female32 5First name is set to Meena Gender is set to Female00 // PHP program to implements encapsulation 1
First name is set to Meena Gender is set to Female47
First name is set to Meena Gender is set to Female12 First name is set to Meena Gender is set to Female13 First name is set to Meena Gender is set to Female51
First name is set to Meena Gender is set to Female58 First name is set to Meena Gender is set to Female04 <?php 6
First name is set to Meena Gender is set to Female62 2First name is set to Meena Gender is set to Female64 First name is set to Meena Gender is set to Female65 First name is set to Meena Gender is set to Female04 First name is set to Meena Gender is set to Female67 First name is set to Meena Gender is set to Female68 First name is set to Meena Gender is set to Female65 First name is set to Meena Gender is set to Female04 <?php 6 |