是否可以使用具有私有/受保护方法的接口? [英] Is it possible to have an interface that has private / protected methods?

查看:64
本文介绍了是否可以使用具有私有/受保护方法的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP 5中是否可以使用具有私有/受保护方法的接口?

Is it possible in PHP 5 to have an interface that has private / protected methods?

现在我有:

interface iService
{
    private method1();
}

抛出错误:


解析错误:语法错误,意外T_STRING,期待T_VARIABLE

Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE

我只想拥有确认接口只能包含公共方法。

I just want to have confirmation that it is the case that an interface can only contain public methods.

推荐答案

关于接口的PHP手册页明确指出:


声明的所有方法在界面中必须是公开的;这是界面的本质。

All methods declared in an interface must be public; this is the nature of an interface.

我想这解释了你得到的错误; - )

I guess this explains the error you are getting ;-)

这篇关于是否可以使用具有私有/受保护方法的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆