Created
March 11, 2012 10:54
-
-
Save meritt/2015976 to your computer and use it in GitHub Desktop.
Traits example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait Hello | |
{ | |
public function sayHello() | |
{ | |
echo 'Hello '; | |
} | |
} | |
trait World | |
{ | |
public function sayWorld() | |
{ | |
echo 'World'; | |
} | |
} | |
class HelloWorld | |
{ | |
use Hello, World; | |
public function sayHelloWorld() | |
{ | |
echo $this->sayHello() . $this->sayWorld() . '!'; | |
} | |
} | |
$o = new HelloWorld(); | |
$o->sayHelloWorld(); // выведет на экран "Hello World!" | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Подробнее о том что еще нового появилось в PHP 5.4 читайте здесь: blog.simonenko.su