Skip to content

Instantly share code, notes, and snippets.

@meritt
Created March 11, 2012 10:54
Show Gist options
  • Save meritt/2015976 to your computer and use it in GitHub Desktop.
Save meritt/2015976 to your computer and use it in GitHub Desktop.
Traits example
<?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!"
?>
@meritt
Copy link
Author

meritt commented Mar 12, 2012

Подробнее о том что еще нового появилось в PHP 5.4 читайте здесь: blog.simonenko.su

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment