SoFunction
Updated on 2025-03-03

Implementation method of single interface of php

This article describes the implementation method of a single interface of PHP. Share it for your reference. The specific implementation method is as follows:

<?php 
  interface staff_i 
  { 
    function setID($id); 
    function getID(); 
    function setName($name); 
    function getName(); 
  } 
  class staff implements staff_i //This class is used to implement the staff_i interface  { 
   private $id; 
   private $name; 
   function setID($id) 
   { 
     $this->id = $id; 
   } 
   function getID()  
   { 
     return $this->id; 
   } 
   function setName($name)  
   { 
     $this->name = $name; 
   } 
   function getName()  
   { 
     return $this->name; 
   } 
   function otherFunc() //This is a method that does not exist in an interface   { 
    echo "Test"; 
   } 
  } 
?>

I hope this article will be helpful to everyone's PHP programming.