php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44033 make working abstract methods body in abstract classes
Submitted: 2008-02-03 18:57 UTC Modified: 2012-10-26 20:24 UTC
Votes:7
Avg. Score:3.3 ± 1.2
Reproduced:6 of 7 (85.7%)
Same Version:3 (50.0%)
Same OS:0 (0.0%)
From: giorgio dot liscio at email dot it Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 5.2.5 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: giorgio dot liscio at email dot it
New email:
PHP Version: OS:

 

 [2008-02-03 18:57 UTC] giorgio dot liscio at email dot it
Description:
------------
hello
i think can be useful make working abstract methods body in abstract classes
please read carefully ;) i hope you like it
thank you for your time

Reproduce code:
---------------
<?php

abstract class Base
{
      abstract protected function commonCheck()
      {
           echo("WOW! ");
      }
}

class Real extends Base
{
      // there I MUST implement the abstract method in all cases
      // the implementation can consists:
      // 1 - in one new procedure,
      // 2 - in parent method calling (used the abstract body like a model)
      // 3 - both
      protected function commonCheck()
      {
            parent::commonCheck();
            echo("IT IS WORKING!");
      }
}

?>

Expected result:
----------------
echo("WOW ");
echo("IT IS WORKING!");

Actual result:
--------------
Fatal error: Abstract function Base::commonCheck() cannot contain body

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-03 20:33 UTC] giorgio dot liscio at email dot it
the requested behavior can works with multiple abstract inheritance

abstract class One
{abstract function m(){echo("one ");}}
abstract class Two extends One
{abstract function m(){parent::m();echo("two ");}}
abstract class Three extends Two
{abstract function m(){parent::m();echo("three ");}}

class RealClass extends Three
{
     function m(){parent::m();echo("real implementation");}
}
 [2011-04-08 21:28 UTC] jani@php.net
-Summary: feature request: make working abstract methods body in abstract classes +Summary: make working abstract methods body in abstract classes -Package: Feature/Change Request +Package: Class/Object related -Operating System: Irrelevant +Operating System: *
 [2012-10-26 15:59 UTC] dagguh at gmail dot com
You obviously don't know what abstract methods are about.

Learn OOP, please. This is what you want:

<?php

abstract class Base
{
      protected final function commonCheck()
      {
           echo("WOW! ");
           $this->customCheck();
      }

     protected abstract function customCheck();
}

class Real extends Base
{

      protected function customCheck()
      {
            echo("IT IS WORKING!");
      }
}

?>
 [2012-10-26 16:02 UTC] dagguh at gmail dot com
To promote OOD, this issue should be closed as "won't fix"
 [2012-10-26 20:24 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2012-10-26 20:24 UTC] nikic@php.net
dagguh has a point. Abstract functions are, well, abstract, so they can't specify an implementation ^^
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 06:01:27 2025 UTC