php5 interfaces...

php.internals

Tony Bibbs

23 years ago
In PHP5 I noticed this behaviou with interfaces. If I have an interface with a method that takes no paramaters, an implementing class for that interfaces can have the same method take parameters...is that right? For example: interface foo { public function myFunction(); } class foobar implements foo { public function myFunction($someText) { echo $someText; } } $myObj = new foobar(); $myObj->myFunction('Testing, 1, 2, 3'); This code works. To me it should flag an error or, at least a warning, no? I can see the flexibility of allowing this as it provides a kind-of form of overloading but I want to make sure this behaves as intended before I make use of this feature/bug. --Tony

(Marcus Börger)

23 years ago
Hello Tony, Friday, July 11, 2003, 9:39:55 PM, you wrote: TB> In PHP5 I noticed this behaviou with interfaces. If I have an interface TB> with a method that takes no paramaters, an implementing class for that TB> interfaces can have the same method take parameters...is that right? TB> For example: TB> interface foo { TB> public function myFunction(); TB> } TB> class foobar implements foo { TB> public function myFunction($someText) TB> { TB> echo $someText; TB> } TB> } TB> $myObj = new foobar(); $myObj->>myFunction('Testing, 1, 2, 3'); TB> This code works. To me it should flag an error or, at least a warning, TB> no? I can see the flexibility of allowing this as it provides a kind-of TB> form of overloading but I want to make sure this behaves as intended TB> before I make use of this feature/bug. TB> --Tony PHP is a wek typed language....i see your point but we are not strict typed. marcus
-- Best regards, Marcus mailto:helly@php.net

Jan Schneider

23 years ago
Zitat von Marcus BXrger <marcus.boerger@t-online.de>:
> Hello Tony, > > Friday, July 11, 2003, 9:39:55 PM, you wrote: > > TB> In PHP5 I noticed this behaviou with interfaces. If I have an > interface > TB> with a method that takes no paramaters, an implementing class for > that > TB> interfaces can have the same method take parameters...is that right? > TB> For example: > > TB> interface foo { > TB> public function myFunction(); > TB> } > > TB> class foobar implements foo { > TB> public function myFunction($someText) > TB> { > TB> echo $someText; > TB> } > TB> } > > TB> $myObj = new foobar(); > $myObj->>myFunction('Testing, 1, 2, 3'); > > TB> This code works. To me it should flag an error or, at least a > warning, > TB> no? I can see the flexibility of allowing this as it provides a > kind-of > TB> form of overloading but I want to make sure this behaves as intended > TB> before I make use of this feature/bug. > > TB> --Tony > > > > PHP is a wek typed language....i see your point but we are not strict > typed.
What does this have to do with typed languages? Interfaces are not types of method implementations or some such. There's also a warning if you call a function/method with too few or too much arguments, that seems much more similar to this case for me. Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - discover your knowledge http://www.tip4all.de - Deine private Tippgemeinschaft

(Marcus Börger)

23 years ago
Hello Jan, Tuesday, July 15, 2003, 11:53:02 PM, you wrote: JS> Zitat von Marcus BXrger <marcus.boerger@t-online.de>:
>> Hello Tony, >> >> Friday, July 11, 2003, 9:39:55 PM, you wrote: >> >> TB> In PHP5 I noticed this behaviou with interfaces. If I have an >> interface >> TB> with a method that takes no paramaters, an implementing class for >> that >> TB> interfaces can have the same method take parameters...is that right? >> TB> For example: >> >> TB> interface foo { >> TB> public function myFunction(); >> TB> } >> >> TB> class foobar implements foo { >> TB> public function myFunction($someText) >> TB> { >> TB> echo $someText; >> TB> } >> TB> } >> >> TB> $myObj = new foobar(); >> $myObj->>myFunction('Testing, 1, 2, 3'); >> >> TB> This code works. To me it should flag an error or, at least a >> warning, >> TB> no? I can see the flexibility of allowing this as it provides a >> kind-of >> TB> form of overloading but I want to make sure this behaves as intended >> TB> before I make use of this feature/bug. >> >> TB> --Tony >> >> >> >> PHP is a wek typed language....i see your point but we are not strict >> typed.
JS> What does this have to do with typed languages? Interfaces are not types of JS> method implementations or some such. JS> There's also a warning if you call a function/method with too few or too JS> much arguments, that seems much more similar to this case for me. A class type or protocol consists of the collection of all properties and methods. A method type consists of its name, its return type and the parameter list with the types. An interface is a special form of an abstract class. Since PHP is weak typed we never check for types unless a typehint is used. The rules for method inheriting and verifying if return/parameter types are the same or the type change is allowed are complex. In other words we could only enforce that a derived method has the same number of parameters. ATM we had a lazy concensus not to test for the number of parameters.
-- Best regards, Marcus mailto:helly@php.net

Zeev Suraski

23 years ago
At 22:39 11/07/2003, Tony Bibbs wrote:
>In PHP5 I noticed this behaviou with interfaces. If I have an interface >with a method that takes no paramaters, an implementing class for that >interfaces can have the same method take parameters...is that right? >For example: > >interface foo { > public function myFunction(); >} > >class foobar implements foo { > public function myFunction($someText) > { > echo $someText; > } >} > >$myObj = new foobar(); >$myObj->myFunction('Testing, 1, 2, 3'); > >This code works. To me it should flag an error or, at least a warning, no?
Yep, it should error out, it's a bug. I'll look into it. Zeev

Zeev Suraski

23 years ago
This bug should be gone now... Thanks for the report! Zeev At 22:39 11/07/2003, Tony Bibbs wrote:

Derick Rethans

23 years ago
On Wed, 16 Jul 2003, Zeev Suraski wrote:
> This bug should be gone now... > > Thanks for the report!
Could you please add a test for this one? regards, Derick
-- "Interpreting what the GPL actually means is a job best left to those that read the future by examining animal entrails." ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ International PHP Magazine http://php-mag.net/ -------------------------------------------------------------------------