Accessing Properties and Methods 2.1.2
Accessing Properties and Methods 2.1.2
CO3 Understand
Students will learn database connectivity, plugin and security
issues.
2
Web Development
Using PHP
Course Outcome • OOP
CO Title Level
Number
• Session and Cookies
Understand
• File handling
CO1
Students will learn basics of PHP • Database
CO2 Understand &
Students will understand the underlying concept of themes in Analyze
wordpress.
CO3 Understand
Students will learn database connectivity, plugin and security
issues.
3
Topic to be Covered
• Accessing properties and methods
4
Accessing properties and methods
• Class member variables are called properties. Sometimes they are referred as attributes
or fields.
• The properties hold specific data and related with the class in which it has been defined.
• Declaring a property in a class is an easy task, use one of the keyword public, protected,
or private followed by a normal variable declaration. If declared using var (compatibility
with PHP 4), the property will be defined as public.
• public : The property can be accessed from outside the class, either by the script or from another
class
• private : No access is granted from outside the class, either by the script or from another class.
• protected : No access is granted from outside the class except a class that’s a child of the class
with the protected property or method.
5
Example:-
After an object is instantiated, you can access the property of a class using
the object and -> operator. Any member declared with keyword "private" or "protected"
cannot be accessed outside the method of the class.
<?php
class Myclass
{
public $font_size =10;
}
$f = new MyClass;
echo $f->font_size; 6
Accessing Methods
• The functions which are declared in a class are called methods.
• A class method is exactly similar to PHP functions.
• Declaring a method in a class is an easy task, use one of the keyword public, protected, or private followed
by a method name.
8
Access Specifiers
9
Class Member Accessible from derived
Access from own class Accessible by Object
Access Specifier class
Private Yes No No
10
Book References
• Php: The Complete Reference, Steven Holzner, Tata McGraw-
Hill Education, 2007
• Modern PHP: New Features and Good Practices, Josh Lockhart,
"O'Reilly Media, Inc.“, 2015.
• PHP for the Web: Visual QuickStart Guide, Larry Ullman
Pearson Education, 2006.
• https://www.tutorialspoint.com/php/index.htm
• https://www.codecademy.com/learn/learn-php
11
THANK YOU