FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » An overloading question
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: An overloading question [message #174525 is a reply to message #174495] Wed, 15 June 2011 16:04 Go to previous messageGo to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma:
Senior Member
.oO(Jerry Stuckle)

> Unfortunately, PHP doesn't really implement OO constructs very well - in
> fact they to a pretty piss poor job of it. One of the problems is with
> virtual functions, as you found. A good OO language would work like you
> want, but PHP doesn't - the constructor for A will, in this case, only
> call a function in A.

What do you mean?

<?php
class A {
public function __construct() {
$this->y();
}

public function y() {
print __METHOD__."\n";
}
}

class B extends A {
public function y() {
print __METHOD__."\n";
}
}

$a = new A();
$b = new B();
?>

$ php -f constructor.php
A::y
B::y

Pretty much what I expect.

> In C++, Smalltalk, Java and most other OO
> languages, you could define y() as virtual and the constructor for A
> would call the function y() in B.

In PHP non-private methods are always virtual and in the above example
the constructor in A calls the method in B.

Micha
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: check user log and redirect
Next Topic: use GET in include
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 17:32:33 GMT 2024

Total time taken to generate the page: 0.09575 seconds