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



On Tue, Apr 29, 2008 at 4:29 PM, Stut <stuttle@xxxxxxxxx> wrote:


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.
Oh, yeah, I've got so used with php 5 that I've completly forgot about
php 4 compatibility

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

Thanks.
-Stut

--
http://stut.net/

.



Relevant Pages

  • Re: Getting the names of variables passed to functions
    ... I'd like the function foo to return a string of the variable name ... but as far as I know PHP doesn't support them. ... public function getValue() ... public var $bar; ...
    (comp.lang.php)
  • Re: Getting the names of variables passed to functions
    ... I'd like the function foo to return a string of the variable name ... but as far as I know PHP doesn't support them. ... public function getValue() ... if you mix the class CVar and your 'fooFactory' you could have a result. ...
    (comp.lang.php)
  • Re: XSLT: Is the variable scope of local?
    ... scoping, but about what a variable's scope is. ... and, say, PHP does not adhere ... if ($foo) { ... Global symbol "$bar" requires explicit package name at ...
    (comp.text.xml)
  • Re: how do i avoid typing the keyword "$this->" every time inside a class
    ... Thinking of it, IMHO, this is a big excuse we (PHP community) give ... Or better still, one could write a slightly complex parsing script, say ... One of the important things here is that PHP allows two $foo variables ... public function showfoo{ ...
    (comp.lang.php)
  • Re: what is the -> operator?
    ... PHP manual at php.net, I can't find a description of what it does. ... class foo ... If I have a class myClass with methods foo and bar ...
    (comp.lang.php)