Re: [PHP] Inherited and unimplemented method of a class




On 29 Apr 2008, at 15:19, Aspra Flavius Adrian wrote:

Hello folks.

An inherited and unimplemented method of a class in PHP-5.2.5 gets called twice:

class Foo {
public function foo() {
echo get_class($this);//or __CLASS__;
}
}
class Bar extends Foo {
}
$f = new Bar;
$f->foo();

Shouldn't it be only once? If I'm doing something wrong, how would I
do it right? If it's a bug, did it get fixed as of 5.2.6RC5 ?

PHP supports two types of constructor. One is __construct(), the other is a function with the same name as the class.

In your example new Bar; will call foo as the constructor for the Foo class, and then you call foo again explicitly.

-Stut

--
http://stut.net/
.



Relevant Pages

  • Re: Insert with response
    ... FooBar, there's no way and no need to put them in synch. ... column in the foo table to 250 calumns in the bar table. ... set statistics time off ...
    (microsoft.public.sqlserver.programming)
  • Re: Magic function
    ... processing objects created in root at depth 3 ... root obj2 at depth 3 ... processing objects created in foo at depth 2 ... processing objects created in bar at depth 0 ...
    (comp.lang.python)
  • Re: from __future__ import absolute_import ?
    ... foo not in bar ... Unfortunately this is a side effect of using the os's directory structure to represent a python "package" structure. ...
    (comp.lang.python)
  • Re: from __future__ import absolute_import ?
    ... foo not in bar ... A path below the package level is generally a good means to shoot ... to represent a python "package" structure. ...
    (comp.lang.python)
  • Re: how to deserialize variable element/node
    ... string bar; ... In the first deserialization case, bar = "sometimes a simple string is ... Your two XML fragments would have to be represented in an XML schema by ...
    (microsoft.public.dotnet.xml)