i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
Traits are used when a class needs to inherit properties or methods from multiple classes. As in PHP, one child class can only inherit from one parent or base class. Traits allows to declare methods that we can use in multiple classes and can have methods and abstract methods. The trait methods can use any of the access modifier. You can declare traits using trait keyword in PHP and to use trait in a class use the use keyword.
Syntax: trait trait_name {
// code including methods or properties
}
For example:
trait greeting {
public function greet() {
echo "Welcome to PHP session! ";
}
}
class Welcome {
use greeting;
}
$visitor = new Welcome();
$visitor ->greet();
?>
In above example, we have declared a trait named greeting and used it in the class Welcome and the methods of the trait will automatically be available in the class using a trait. Similarly, you can use multiple traits in any class.
Don't miss out!