NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 Interfaces

Michael Hernandez sequethin at gmail.com
Tue May 26 16:07:38 EDT 2009


On Tue, 2009-05-26 at 16:02 -0400, Joseph Crawford wrote:
> Guys in the past I have used interfaces and have do not recall hitting
> this issue.
> 
> 
> I have the following interface
> 
> 
> <?php
> 
> 
> interface Pagable
> {
> private function getPreviousPage();
> private function getNextPage();
> private function getCurrentPage();
> private function getStartPage();
> private function getLastPage();
> private function getTotalPages();
> 
> public function getPageString();
> public function getTotalResults();
> }
> 
> 
> class YP_Listing_Handler implements Pagable
> {
> 
> 
> ...
> private function getPreviousPage()
> {
> return $this->getCurrentPage() - 1;
> 
> }
> ...
> }
> 
> 
> I keep getting this error.
> 
> 
> Fatal error: Access type for interface method
> Pagable::getPreviousPage() must be omitted
> in /Applications/MAMP/htdocs/yp/inc/Pagable.php on line 5
> 
> 
> 
> 
> I am not sure what is causing it but if I remove the private keyword
> then it complains that it must be declared public in the class.
> 
> 
> Is there a reason I cannot declare a method as being private in the
> interface?
> 
> 
> Thanks,
> Joseph Crawford
> 

Interfaces are, by design, intended to have public methods that are
supposed to be implemented by classes that implement the interface with
the implements keyword. At least thats the way the books I've read
explain it.

--Mike H





More information about the talk mailing list