Created
August 6, 2019 14:19
-
-
Save jonnybarnes/c10568351c3122bd5a34f002eb35bbc4 to your computer and use it in GitHub Desktop.
Used in my PHP Traits post for BuildEmpire
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 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