[SOLVED] Weird problem with abstract classes and interfaces
Posted: Sat Jan 01, 2005 9:43 am
Hello,
I have an abstract class implementing an interface. This abstract class doesn't contain all of the methods required by the interface. I have a second class that inherits from the first one and contains the missing methods. The code produces no error, but doesn't work.
Simple examle:
This way of coding is no problem in Java, but doesn't seem to work in PHP5. Any explanation or workaround is beeing appreciated. Everything tested on Linux with PHP 5.0.3 on Apache 1.3.33.
Lars
feyd | Help us, help you. Please use
I have an abstract class implementing an interface. This abstract class doesn't contain all of the methods required by the interface. I have a second class that inherits from the first one and contains the missing methods. The code produces no error, but doesn't work.
Simple examle:
Code: Select all
<?php
interface MyInterface {
public function printTest();
}
abstract class A
implements MyInterface {
protected $testString = "Hello world";
}
class B
extends A{
public function printTest() {
echo($testString);
}
}
$obj = new B();
$obj->printTest();
?>Lars
feyd | Help us, help you. Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]