php interface Interface Usage

1. Simple animal demo

<? PHP
 # simple to understand and use interface 
# in my understanding of java in the interface is the definition of the interface variables and constants and methods to be integrated with the realization

# Define an interface animal animals have favorite foods, and eat way 
interface Animal
{
    const Foot = 'bone'; // define a constant food

    public  function EAT (); // define a method where food can increase attention brackets 
}

# Define a class that implements the interface method 
# dogs are animals will eat it can be inherited interface method 
class Dog the implements Animal
{
    public function eat()
    {
       echo 'I am the only dog I love' .self :: Foot;
    }
}

# Instantiated dog

$wangcai=new dog();

wangcai $ -> EAT ();
 # Output: I just love my dog bones

 

Guess you like

Origin www.cnblogs.com/yaoliuyang/p/12610522.html