Answers for "abstract class php"

4

php interface vs abstract class

Use an interface when you want to force developers working in your 
system (yourself included) to implement a set number of methods on the 
classes they'll be building.
Use an abstract class when you want to force developers working in your 
system (yourself included) to implement a set numbers of methods and you 
want to provide some base methods that will help them develop their child 
classes.
Another thing to keep in mind is client classes can only extend one abstract 
class, whereas they can implement multiple interfaces. So, if you're 
defining your behavior contracts in abstract classes, that means each child 
class may only conform to a single contract. Sometimes this a good thing, 
when you want to force your user-programmers along a particular path. Other 
times it would be bad. Imagine if PHP's Countable and Iterator interfaces 
were abstract classes instead of interfaces.
One approach that's common when you're uncertain which way to go (as 
mentioned by cletus below) is to create an interface, and then have your 
abstract class implement that interface.
Posted by: Guest on October-30-2020
1

abstract class in php

<?php
/**
 * abstract means incomplete
 * abstract class contains atleast 1 abstract function
 * abstract function:- we must declare it but not implement it, it can not contain body
 * you can't create object of abstract method
 * abstract class, child class must contain abstract function
 */
abstract class Bank
{
    abstract function id_proof();
}
class Hdfc extends Bank
{
    function id_proof()
    {
        echo "hdfc bank";
    }
}
class Axis extends Bank
{
    function id_proof()
    {
        echo "<br>axis bank<br>";
    }
}

$obj = new Axis();
$obj -> id_proof();

$obj1 = new Hdfc();
$obj1 -> id_proof();
?>
Posted by: Guest on October-05-2021
4

abstract function php

abstract class absclass { // mark the entire class abstract
    abstract public function fuc();
}
Posted by: Guest on June-06-2021
0

PHP OOP - Abstract Classes

<?php
abstract class 
    ParentClass {
  abstract public function someMethod1();
  
    abstract public function someMethod2($name, $color);
  abstract 
    public function someMethod3() : string;
}
?>
Posted by: Guest on May-28-2021

Code answers related to "abstract class php"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language