Re: An overloading question [message #174527 is a reply to message #174525] |
Wed, 15 June 2011 16:53 |
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
==================
|
|
|