php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #18530 Request for Delphi style "inherited" call
Submitted: 2002-07-24 04:11 UTC Modified: 2002-07-24 04:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: woprog at hotmail dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4.1.2 OS: Any
Private report: No CVE-ID: None
 [2002-07-24 04:11 UTC] woprog at hotmail dot com
This is a feature request, not a bug.
=====================================


Check the following code:

class A {
  function foo() { echo "A bar"; }
}

class B extends A {
  function foo() { echo "B bar"; }
}

When I want to call the parent version of the function foo() in B, I have to enter:

A::foo();

thus including the actual classname of its parent... for me this is really annoying (I work a lot with classes in PHP)... could it be possible that the Delphi style of calling some classes parent version of some function is included in PHP? In Delphi this would look like this:

type
  A = class
    function foo();
  end;

  B = class(A)
    function foo();
  end;

function A.foo()
begin
  // do something
end;

function B.foo()
  inherited; // would call A.foo
  // do something else
end;


As you can see in the Delphi code, there's no need to include the actual class name in the call. This is possible since Delphi doesn't support multiple inheritance. And as far as I know, PHP doesn't as well, so it should be possible, right?

Would be really great to get feedback on this...

Marc

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-24 04:22 UTC] alan_k@php.net
you can already do

parent::foo();

the inherited; is really against the grain of the language as it is a little too obfusicated.
 [2002-07-24 04:27 UTC] woprog at hotmail dot com
Hmm is that anywhere in the documentation? That also means that classes with the name "parent" are not possible right?

Thanks a lot!!
 [2002-07-24 04:35 UTC] derick@php.net
You can have a class named parent, but you can not access it as a static class:

Derick
 [2002-07-24 04:37 UTC] alan at akbkhome dot com
http://www.php.net/manual/en/keyword.parent.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 19:01:30 2024 UTC