On 4 June 2013 09:57, Richard Quadling <rquadl...@gmail.com> wrote:

> On 3 June 2013 20:37, shiplu <shiplu....@gmail.com> wrote:
>
>> Show a short reproducible code.
>>
> And I can now see an interface is a much simpler mechanism!
>

<?php
interface baseInterface {
    static public function generateLocalisedContent($s_Stuff);
}

abstract class baseClass implements baseInterface {
    public function __construct($s_Stuff) {
        echo static::generateLocalisedContent($s_Stuff);
    }
}

class sub1 extends baseClass{}

class sub2 extends baseClass{
    static public function generateLocalisedContent($s_Stuff){
        return 'Your stuff is ' . $s_Stuff . PHP_EOL;
    }
}

try {
    $o1 = new sub1('Stuffed1');
}
catch(Exception $ex){
    echo $ex->getMessage(), PHP_EOL;
}

try {
    $o2 = new sub2('Stuffed2');
}
catch(Exception $ex){
    echo $ex->getMessage(), PHP_EOL;
}

?>

PHP Fatal error:  Class sub1 contains 1 abstract method and must therefore
be declared abstract or implement the remaining methods
(baseInterface::generateLocalisedContent) in - on line 12

A much more meaningful error.


-- 
Richard Quadling
Twitter : @RQuadling
EE : http://e-e.com/M_248814.html
Zend : http://bit.ly/9O8vFY

Reply via email to