|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 10:00:01 2025 UTC |
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");} }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!"); } } ?>