php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51826 maybe a wrong oop logic.
Submitted: 2010-05-14 17:15 UTC Modified: 2012-07-03 00:34 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: 1000235409 at smail dot shnu dot edu dot cn Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 5.3SVN-2010-05-14 (SVN) OS: WINDOWS
Private report: No CVE-ID: None
 [2010-05-14 17:15 UTC] 1000235409 at smail dot shnu dot edu dot cn
Description:
------------
A fatal error generates when a class extends from an abstract class and implements 
from an interface both with a same named abstract (all methods defined inside 
interfaces are abstract) method inside.

Test script:
---------------
<?php
abstract class TAbstractParam {
  public abstract function getType(); //getType
}

interface IParam {
  public function getType(); //getType again.
}

class TPrimativeParam extends TAbstractParam implements IParam {
  public function getType() {return 'VARCHAR'; } //another getType, the fatal error goes here.
}

Expected result:
----------------
[just nothing...]


Actual result:
--------------
Fatal error: Can't inherit abstract function IParam::getType() (previously 
declared abstract in TAbstractParam) in E:\foo.php on line 10

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-14 17:42 UTC] 1000235409 at smail dot shnu dot edu dot cn
I have adapted those code(see it below) into delphi(object pascal, on 
Delphi2010), however, nothing wrong at all. so i think it should be a wrong oop 
logic in php5(5.2 included also, since i've tested then...)

Type
  TAbstractParam = Class(TInterfacedObject)
    Procedure getType(); Virtual; Abstract;
  End;

  IParam = Interface
    Procedure getType();
  End;

  TPrimativeParam = Class(TAbstractParam, IParam)
    Procedure getType();
  End;
//Other code omitted...
 [2010-05-17 19:51 UTC] crrodriguez at opensuse dot org
Expected behaviour, your code causes ambiguity.
 [2010-05-18 01:35 UTC] 1000235409 at smail dot shnu dot edu dot cn
there are other non-abstract methods inside the abstract class to provide some base behaviors for its children claclasses, which i omitted in this example. and those non-abstract methods may call the abstract methods. and an abstract class should not be defdefined as an instance cclass for an interface cuz an non-abstract one should, so why ambiguity?
 [2010-05-22 16:21 UTC] 1000235409 at smail dot shnu dot edu dot cn
<?php
abstract class TAbstractParam {
  protected $FValue = null;
  public abstract function getType(); //getType
  public function Dump() {
    return "TYPE=" . $this->getType() . " VALUE=" . $this->FValue;
  }
}

interface IParam {
  public function getType(); //getType again.
}

class TStringParam extends TAbstractParam implements IParam {
  public function getType() {return 'VARCHAR'; } //another getType, the fatal 
error goes here.
}


see this example, please...
 [2012-07-02 13:13 UTC] j dot henge-ernst at interexa dot de
Seems to be fix with PHP 5.3.9
 [2012-07-03 00:34 UTC] aharvey@php.net
-Status: Open +Status: Duplicate
 [2012-07-03 00:34 UTC] aharvey@php.net
Duplicate of bug #43200, which has now been fixed, as you've noted.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 18:01:28 2024 UTC