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 #174527 is a reply to message #174525] Wed, 15 June 2011 16:53 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 6/15/2011 12:04 PM, Michael Fesser wrote:
> .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

Ah, you're right, Micha. This was finally fixed. It didn't used to
work that way :)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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:36:38 GMT 2024

Total time taken to generate the page: 0.04469 seconds