Skip to content

Instantly share code, notes, and snippets.

@jonnybarnes
Created August 6, 2019 14:19
Show Gist options
  • Save jonnybarnes/c10568351c3122bd5a34f002eb35bbc4 to your computer and use it in GitHub Desktop.
Save jonnybarnes/c10568351c3122bd5a34f002eb35bbc4 to your computer and use it in GitHub Desktop.
Used in my PHP Traits post for BuildEmpire
<?php
trait One
{
public function hello()
{
echo 'Hello One' . PHP_EOL;
}
public function bye()
{
echo 'Bye One' . PHP_EOL;
}
}
trait Two
{
public function hello()
{
echo 'Hello Two' . PHP_EOL;
}
}
class SomeClass
{
use One, Two {
Two::hello insteadof One;
}
}
$someClass = new SomeClass();
$someClass->hello();
$someClass->bye();
// The above will output
// Hello Two
// Bye One
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment