|
Posted by Sergio Gorelyshev on 01/21/05 10:07
On Thu, 20 Jan 2005 11:13:11 -0800 (PST)
"Richard Lynch" <ceo@l-i-e.com> 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.
>
> As I understand it, an 'interface' is, by definition, never gonna have an
> actualy object instantiated.
>
> Thus, there can never *BE* an object for which private/public/protected
> have any meaning.
>
> You can only use the private/public/protected on the 'class' definitions.
Thanks to all.
First sample of interface usage in php manual:
<?php
interface ITemplate
{
public function setVariable($name, $var);
public function getHtml($template);
}
class Template implements ITemplate
{
private $vars = array();
public function setVariable($name, $var)
{
$this->vars[$name] = $var;
}
public function getHtml($template)
{
foreach($this->vars as $name => $value) {
$template = str_replace('{'.$name.'}', $value, $template);
}
return $template;
}
}
?>
IMHO its normally to use access type for methods declaration in interfaces. Why not?
Maybe my first example was not sufficiently illustrative. But my question was "why it does not work in one environment and work fine in another". The problem has acquired when i try to add "static" in my interface definition. I don't think that this is a bug in PHP. I just want to be deep insight in OOP of PHP5 engine.
> Even if you *KNOW* that all class definitions *should* for this to be
> 'public' it just doesn't make sense from the strictly technical
> stand-point of what an 'interface' is to declare it there.
>
> Maybe somewhere over on php-dev you could make the case for the PHP Dev
> Team to implement something good/interesting when public/protected/private
> is used there, but currently it's semanticly undefined to have it there,
> so it can't be there.
>
> Disclaimer: I could easily be 100% wrong in this entire post. :-)
>
> --
> Like Music?
> http://l-i-e.com/artists.htm
>
--
RE5PECT
Sergio Gorelyshev
Navigation:
[Reply to this message]
|