There are several predefined interfaces in PHP that compare four commonly used interfaces (countable,arrayaccess,Iterator, Iteratoraggregate (converged aggregate iterator iterator)).
1. Countable interface
As seen from the manual, the main class implementation countable can be used with the count () function.
Example:
<?PHPclassconutme{protected $_mycount= 3; Public function Count() { return $this-_mycount; }}$countable=NewConutme ();Echo Count($countable);///result is "1" and not as expected//implements interface countableclassCountMeImplementscountable{protected $_myc= 4; Public function Count() { return $this-_myc; }}$countable=NewCountMe ();Echo Count($countable);//result is "4" as expected
Summarize:
Countable this interface is used to count the number of objects, and when count is called on an object, if the class (such as CountMe) does not inherit countable, it will always return 1 if the inherited countable returns the number returned by the implemented Count method.
2. Arrayaccess Interface
Very often, the framework implements this interface. Key Features: Provides an interface to access objects as you would access an array. (read more about PHP using array syntax to access objects)
3.Iterator interface
PHP SPL Common Interface