Re: Re: php 5 interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



M. Sokolewicz wrote:
Sergio Gorelyshev wrote:

Hi all.

Situation:

interface MyInterface {
 public static myMethod();
}

class MyClass implements MyInterface {
  public static myMethod() {}
}

This sample will crash with message Fatal error: Access type for interface method MyInterface::myMethod() must be omitted in somefile.php on line NN

Why I'm not able to clarify call's type (static) for methods in interface? I'm predict closely that method myMethod() in all classes which implements MyInterface must be called statically. A little trick allowed to me to resolve this problem, but my question more ideological than practical.

Thanks

it's not the static part, it's the public part. You can't make non-public static methods. It's simply impossible by the definition of protected and private (both allow only the object itself to access it, or (in case of protected) a descendent).


So, removing the public part should work out fine.

you are half right but for the wrong reason. think about the word 'interface' for a moment! its illogical for a interface to define a protected/private method (don't argue the gods have already decided :-) and its therefore been decided that interfaces are not allowed to have access types defined.


the bit where you are wrong is that its quite feasable to have private or protected methods - heres a quick grep ('static private function') of some of my code:

include\class\ExchRates.class.php(164): static private function getConstants()
include\class\Img.class.php(35): static private function checkGD()
include\class\ImgChanger.class.php(124): static private function &changeGamma($imgFile, $gamma)
include\class\Lang.class.php(453): static private function _setLang($lang = null)
include\class\Lang.class.php(646): static private function callSmartyModifier($string = '', $modifier = '')
include\class\Msg.class.php(124): static private function translate(&$text = '', $formatMask = 0)
include\class\Msg.class.php(136): static private function stringify(&$value)
include\class\Upload.class.php(122): static private function buildFiles($force = false)
include\class\Zipper.class.php(124): static private function checkforZIP()
include\class\auth\Auth.class.php(117): static private function getSessionKey()
include\class\auth\Session.class.php(240): static private function loadRegisteredClasses()
include\class\auth\Session.class.php(291): static private function privatizeCaching()
include\class\auth\Session.class.php(318): static private function chkSessionVarName($varName)
include\class\dynabyte\Comparison.class.php(374): static private function array_unique($arr)
include\class\dynabyte\Form.class.php(138): static private function setup()
include\class\dynabyte\Form.class.php(400): static private function checkAuthSubmit( $type )
include\class\dynabyte\Form.class.php(438): static private function sendEmail( $type )
include\class\dynabyte\Form.class.php(477): static private function getSuspectedCustomer()
include\class\dynabyte\Form.class.php(569): static private function getEmailAddr( $type )
include\class\dynabyte\Form.class.php(592): static private function getCheckedValues( $type )
include\class\persistent\Persistent.class.php(510): static private function getSelectClause($className)
include\class\persistent\Persistent.class.php(564): static private function getSelectQuery($className,$first, $skip)
include\class\persistent\Persistent.class.php(576): static private function getSelectCountClause($className)
include\class\persistent\Persistent.class.php(614): static private function getSelectCountQuery($className)
include\class\persistent\Persistent.class.php(623): static private function getSQLFieldItem($class, $field, $dir = null)
include\class\persistent\Persistent.class.php(655): static private function getOrderBy($class, $order)
include\class\persistent\ResourceFormat.class.php(68): static private function getExtensions( $format )
include\class\persistent\ResourceFormat.class.php(95): static private function getConstants()
include\class\view\Editizer.class.php(37): static private function singleton()
include\class\view\RowHandlers.class.php(122): static private function getCustomHandlers($entityName, $interface)
include\class\view\RowHandlers.class.php(146): static private function checkHandlers($entityName, $handlers, $popUpURL = '')





-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux