PHP OOP: Traits

What is Traits?

  • Code is shortened by using Traits.
  • One code is used everywhere just by writing the trait function.

Example :

Output:

Multi traits use example:

Output:

Tagged : / / / / / / / / / / / / / /

PHP OOP: Late Static Binding

Late static Binding:

  • Late static binding helps to override name by using static in echo keyword.
  • It helps lot for writing minimum coding.
  • The message of the base class is printed using the self keyword and the message of the derived class is printed using the static keyword.

Example to printing the message of base class:

Output:

Example of printing the message of derived class:

Output:

Tagged : / / / / / / / / / / / /

PHP OOP : Static Members

What is Static Members ?

  • Static properties and methods can be used without creating an instance of the class.
  • The static keyword is used to declare properties and methods of a class as static.
  • Object not create.
  • Stack keyword use before access modifier.
  • Inside class use self::(use static method).
  • inherit use parent class name ::(properties).

Example :

Example Constructor :-

Tagged : / / / / / / / / / / / / /

PHP OOP : Interfaces

What is Interfaces?

  • Interfaces help us to use multiple classes in a single class inherit.
  • Interfaces are declared with the interface keyword.
  • Derived class is called derived class.
  • object not be created in interface.
  • Property should not be defined in interface(class).
  • All interface methods must be public.
  • All methods in an interface are abstract.
  • To implement an interface, a class must use the implements keyword.

Example :-

Tagged : / / / / / / / / / / / / / /

PHP OOP : Abstract Classes

Abstract Class :

  • when we create abstract class then we can not create object of that abstract class.
  • If we want to use abstract class then we only access with derived class .
  • Just abstract write before the class name.
  • when we create abstract class two condition occurs one is abstract method like :- abstract protected function name ( );
  • abstract means incomplete method we declare but not implement (code).
  • In derived class we have to implement of that abstract method.
Tagged : / / / / / / / / / / / /

PHP OOP : Access Modifier (public, protected, private)

What is the access modifier?

Restrictions on properties and methods.

Types of access modifier

  1. public
  2. protected
  3. private

Public :

  • Access on base as well as derived class and outside of the class.
  • Everyone can see and access the data.
  • Not secure.
  • Override use.

Protected :

  • Base and Derived class.
  • No one gets access throughout the class.
  • Declare like protected property and method.
  • Not use override function.
  • Without permission no one can access any of these (properties & method).

Private :

  • Access itself.
  • Highly secured.
  • No one can access without permission.
  • Highly costly.
Tagged : / / / / / / / / / / / / / / /

PHP OOP : Inheritance

What is inheritance in php?

  • Inheritance is properties of PHP.
  • Accessing the feature of one class of another class.
  • Three types that is single, multiple and multilevel inheritance.
  • It is the four pillars of oops.
  • It allows a class to reuse the code from another class without duplicating it.
  • Two classes one is base/main another one is derived class.
  • Base class only use its own function but in Derived class it use both function base or derived class.

How to use inheritance in php?

class school {
}
class students extends school {
}
$sch =new school (); // only use class school 
$stu = new students (); // use both class school students (properties and methods)

Example of main/base class use :-

Example of inheritance:

Tagged : / / / / / / / / / / / / / /

PHP OOP : Constructor function

What is Constructor ?

Constructor is a special type of function of a class which is automatically executed when object of that class is created. Constructor is also called as magic function because in php constructor is start usually with two underscore characters. It saves lot of time on big project.

function __constructor(){
body part;
}

Example of Constructor :-

Tagged : / / / / / / / / / / / /

JavaScript : Where to use javaScript code

JavaScript code use in following :

  1. Between the body tag of html
  2. Between the head tag of html
  3. In .js file (external javaScript)

1. JavaScript use between html body tag :

Example of javaScript using inside html between body tag.

Output :- Hello World

2. JavaScript use between head tag in html :

Example to use javaScript between head tag in html.

Output :

3. External JavaScript file :

We can create external JavaScript file and embed it in many html page. If you want to run the same JavaScript on several pages in a web site, you should create an external JavaScript file, instead of writing the same script over and over again.

message.js

index.html

Tagged : / / / / / / / / / / /

JavaScript : Introduction

JavaScript :

  • JavaScript is used to create client-side dynamic pages.
  • JavaScript (js) is a light-weight object-oriented programming language.
  • JavaScript is not a compiled language, but it is a translated language.
  • The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.
  •  JavaScript, users can build modern web applications to interact directly without reloading the page every time.
  • databases such as CouchDB and MongoDB uses JavaScript as their scripting and query language.

Features of JavaScript :

There are following features of js :-

  • Object-Centered Script Language
  • Light Weight and delicate
  • Interpreted language
  • Case Sensitive format/language
  • Ability to perform In Built Function
  • Statements Looping
  • Client edge Technology
  • Validation of User’s Input
  • Else and If Statement
  • It uses prototypes rather than using classes for inheritance.
  • It is supportable in several operating systems including, Windows, macOS, etc.
  • It provides good control to the users over the web browsers.

Application of JavaScript

JavaScript is used to create interactive websites. It is mainly used for:

  • Client-side validation
  • Manipulating HTML Pages
  • User Notifications
  • Dynamic drop-down menus
  • Displaying date and time
  • Displaying pop-up windows 
  • Alert dialog box
  • Confirm dialog box
  • Prompt dialog box
  • Back-end Data Loading
  • Presentations
  • Server Applications
  • Displaying clocks etc.

JavaScript Example :

Output :-

Welcome to JavaScript

Hello JavaScript by JavaScript

Tagged : / / / / / / / / / / / / / /