PHP Tutorials

Traits in PHP Part – 1 0

Traits in PHP Part – 1

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php trait display { public function displaydata() { echo “Hello Friends How are you this is display data method…..<br>”; } } trait show { public function showdata() {...

PHP strict_types with Examples 0

PHP strict_types with Examples

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php function rev( string $s) { echo strrev($s); } rev(‘Indore’); // class First // { // public function display() // { // echo “This is display method of...

PHP Static Variables with Examples 0

PHP Static Variables with Examples

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php class Myclass { public static $n=0; function __construct() { ++self::$n; } function display() { echo “Total Object: “.self::$n; echo “<br>”; } } // Create Object $M1=new Myclass();...

Method Overriding in PHP 0

Method Overriding in PHP

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php class Base { public function calculation($m,$n) { echo “Addtion is : “.$m+$n; } } class Derived extends Base { public function calculation($m,$n) { echo “Sub is :...

Method Overloading in PHP 0

Method Overloading in PHP

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php class Myclass { function __call($name,$args) { if($name==’area’) { if(count($args)==0) return 0; elseif(count($args)==1) return 3.14*$args[0]*$args[0]; elseif(count($args)==2) return $args[0]*$args[1]; } if($name==’add’) { if(count($args)==0) return 0; elseif(count($args)==1) return $args[0]+0; elseif(count($args)==2)...

Late Static Bindings in PHP 0

Late Static Bindings in PHP

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php class First { protected static $username=”Vikas Sharma”; function display() { echo static::$username; } } class Second extends First { protected static $username=”Rahul Gupta”; } $f=new First(); $f->display();...

PHP OOP Interfaces 0

PHP OOP Interfaces

Program 1 <html> <head><title>Demo Interface</title></head> <body> <center> <?php interface Button { function click(); } interface Key { function keypress(); } class MyColor implements Button,Key { function click() { echo “<font color=red size=7>Color is Red...

PHP OOP Abstract Classes 0

PHP OOP Abstract Classes

Program 1 <html> <head><title>Demo</title></head> <body> <center> <?php abstract class Base { abstract function display(); } class Derived extends Base { function display() { echo “This is display of Derived”; } } class Derived1 extends...

PHP OOPs Access Specifiers 0

PHP OOPs Access Specifiers

Program 1 <html> <head><title>Demo Access Specifier</title></head> <body> <center> <?php class Base { protected $rno=101; protected $name=”Rajesh Verma”; protected $course=”MTech”; } // is A Relation class Derived extends Base { public function display() { echo...

PHP OOPs Constructor 0

PHP OOPs Constructor

Program 1 <html> <head><title>Constructor Demo</title></head> <body> <center> <?php class MyClass { private $rno; private $name; private $course; function __construct($r,$n,$c) // Prameterized constructor { $this->rno=$r; $this->name=$n; $this->course=$c; } function display() { echo “<br>Roll No: “.$this->rno;...