Sunday, June 3, 2018

php - Is it possible to have an interface that has private / protected methods?



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



Right now I have:



interface iService
{
private method1();

}


That throws an error:




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.



Answer



The PHP manual page about interfaces explicitly states:




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 ;-)


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...