예제 #1
0
<?php

error_reporting(E_ALL);
trait THello
{
    public function a()
    {
        echo 'A';
    }
}
class TraitsTest
{
    use THello {
        a as b;
    }
}
$test = new TraitsTest();
$test->a();
$test->b();
예제 #2
0
<?php

error_reporting(E_ALL);
trait THello
{
    public abstract function hello();
}
trait THelloImpl
{
    public function hello()
    {
        echo 'Hello';
    }
}
class TraitsTest
{
    use THello;
    use THelloImpl;
}
$test = new TraitsTest();
$test->hello();
예제 #3
0
--TEST--
Non-conflicting properties should work just fine.
--FILE--
<?php 
error_reporting(E_ALL);
trait THello1
{
    public $hello = "hello";
}
trait THello2
{
    private $world = "World!";
}
class TraitsTest
{
    use THello1;
    use THello2;
    function test()
    {
        echo $this->hello . ' ' . $this->world;
    }
}
var_dump(property_exists('TraitsTest', 'hello'));
var_dump(property_exists('TraitsTest', 'world'));
$t = new TraitsTest();
$t->test();
?>
--EXPECTF--
bool(true)
bool(true)
hello World!
예제 #4
0
파일: 2049.php 프로젝트: badlamer/hhvm
error_reporting(E_ALL);
trait T1
{
    public function getText()
    {
        return $this->text;
    }
}
trait T2
{
    public function setTextT2($val)
    {
        $this->text = $val;
    }
}
class TraitsTest
{
    use T1;
    use T2;
    private $text = 'test';
    public function setText($val)
    {
        $this->text = $val;
    }
}
$o = new TraitsTest();
var_dump($o->getText());
$o->setText('foo');
var_dump($o->getText());
$o->setText('bar');
var_dump($o->getText());