Re: [PHP] php 5 interfaces

2005-01-21 Thread Sergio Gorelyshev
On Thu, 20 Jan 2005 11:13:11 -0800 (PST)
Richard Lynch [EMAIL PROTECTED] 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

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



[Fwd: Re: [PHP] php 5 interfaces]

2005-01-21 Thread Jochem Maas
Tbird switched the reply and reply-all buttons again ;-)...
? 
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. 
it worked for a while because it was originally overlooked, then they
'fixed' it. -- you may not agree with the devs.
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.

your right, its not a bug - although some have argued that its Sucks(tm).
in short it was decided by the devs that interfaces are not meant for
static classes, they only apply to objects - which is why 'static' is
not (no longer) allowed on interface methods. if you want to know more
then digging into the php internals mailing list archives will give you
long discussions and justifications as to why it works they way it does.
if you think about it you can see where they are coming from: passing
around classes (i.e. classNames) and then checking whether said class
implements something is really odd, instead you pass around objects.
or more simply:
class == blueprint
object == house
you can interface with a house (lets hope your house IMPLEMENTS a door
interface!) but you can't interface with a blueprint (possibly with the
piece of paper it may be printed on but not with the actual blueprint)
because the blueprint is an idea/concept.
hope that helps you to understand the rationale.
rgds,
JOchem

...

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


Re: [Fwd: Re: [PHP] php 5 interfaces]

2005-01-21 Thread Sergio Gorelyshev
On Fri, 21 Jan 2005 11:56:55 +0100
Jochem Maas [EMAIL PROTECTED] wrote:

 Tbird switched the reply and reply-all buttons again ;-)...
 
  ? 
  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. 
 
 it worked for a while because it was originally overlooked, then they
 'fixed' it. -- you may not agree with the devs.
 
  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.
  
 
 your right, its not a bug - although some have argued that its Sucks(tm).
 
 in short it was decided by the devs that interfaces are not meant for
 static classes, they only apply to objects - which is why 'static' is
 not (no longer) allowed on interface methods. if you want to know more
 then digging into the php internals mailing list archives will give you
 long discussions and justifications as to why it works they way it does.
 
 if you think about it you can see where they are coming from: passing
 around classes (i.e. classNames) and then checking whether said class
 implements something is really odd, instead you pass around objects.
 
 or more simply:
 
 class == blueprint
 object == house
 
 you can interface with a house (lets hope your house IMPLEMENTS a door
 interface!) but you can't interface with a blueprint (possibly with the
 piece of paper it may be printed on but not with the actual blueprint)
 because the blueprint is an idea/concept.
 
 hope that helps you to understand the rationale.

Thanks. This really helped me to understand php developer's way of thinking.

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


-- 
RE5PECT
Sergio Gorelyshev

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



[PHP] php 5 interfaces

2005-01-20 Thread Sergio Gorelyshev
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
-- 
RE5PECT
Sergio Gorelyshev

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



Re: [PHP] php 5 interfaces

2005-01-20 Thread Richard Lynch
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.

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

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



Re: [PHP] php 5 interfaces

2005-01-20 Thread Jochem Maas
Richard Lynch 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.
true but thats not the reason - the reason is because an interface is a 
PUBLIC contract which a class adheres to.

Thus, there can never *BE* an object for which private/public/protected
have any meaning.
private/public/protected have meaning for static/abstract classes.
You can only use the private/public/protected on the 'class' definitions.
I think that should be 'in' iso 'on'
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. :-)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php