How to create an interface composed of other interfaces

0 votes

I'd like to create an interface, IFoo, that's basically a combination of a custom interface, IBar, and a few native interfaces, ArrayAccess, IteratorAggregate, and Serializable. PHP doesn't seem to allow interfaces that implement other interfaces, as I get the following error when I try:

PHP Parse error: syntax error, unexpected T_IMPLEMENTS, expecting '{' in X on line Y

I know that interfaces can extend other ones, but PHP doesn't allow multiple inheritance and I can't modify native interfaces, so now I'm stuck.

Do I have to duplicate the other interfaces within IFoo, or is there a better way that allows me to reuse the native ones?

Nov 5, 2020 in PHP by kartik
• 37,520 points
502 views

1 answer to this question.

0 votes

Hello,

You are looking for the extends keyword:

Interface IFoo extends IBar, ArrayAccess, IteratorAggregate, Serializable
{
    ...
}

Hope it works!!

answered Nov 5, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to resolve “must be an instance of string, string given” prior to PHP 7?

Hello, Prior to PHP 7 type hinting can only be ...READ MORE

answered Apr 20, 2020 in PHP by I Navin
• 220 points
5,162 views
0 votes
0 answers

How do I create a copy of an object in PHP?

As far as I know, PHP objects ...READ MORE

Jun 1, 2022 in PHP by Kichu
• 19,040 points
436 views
0 votes
0 answers

How to sort an array of associative arrays by value of a given key in PHP?

Given this array: $inventory = array( ...READ MORE

Jul 24, 2022 in PHP by Kithuzzz
• 38,000 points
668 views
0 votes
0 answers

How to generate a create table script for an existing table in phpmyadmin?

How can I generate a create table ...READ MORE

Aug 4, 2022 in PHP by Kithuzzz
• 38,000 points
896 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,081 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,017 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,949 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,889 views
0 votes
1 answer

How to check an IP address is within a range of two IPs in PHP?

Hello @kartik, With ip2long() it's easy to convert your addresses ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,840 points
3,639 views
0 votes
1 answer

What is a Cookie? How to create Cookies With PHP?

A cookie is often used to identify ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,817 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP