Esempio n. 1
0
<?php

error_reporting(E_ALL);
trait Hello
{
    public function sayHello()
    {
        echo 'Hello ';
    }
}
trait World
{
    public function sayWorld()
    {
        echo 'World';
    }
}
class MyHelloWorld
{
    use Hello, World;
    public function sayExclamationMark()
    {
        echo '!';
    }
}
$o = new MyHelloWorld();
$o->sayHello();
$o->sayWorld();
$o->sayExclamationMark();
Esempio n. 2
0
error_reporting(E_ALL);
abstract class Base
{
    public abstract function sayHello(array $a);
}
class SubClass extends Base
{
    public function sayHello(array $a)
    {
        echo "World!\n";
    }
}
$s = new SubClass();
$s->sayHello(array());
trait SayWorld
{
    public function sayHello(Base $d)
    {
        echo 'World!';
    }
}
class MyHelloWorld extends Base
{
    use SayWorld;
}
$o = new MyHelloWorld();
$o->sayHello(array());
?>
--EXPECTF--

Fatal error: Declaration of SayWorld::sayHello() must be compatible with Base::sayHello(array $a) in %s on line %d, position %d