Created
October 4, 2019 03:33
-
-
Save greg-1-anderson/c249e18a04c53502294795ad7326f68d to your computer and use it in GitHub Desktop.
Example of trait with private
This file contains 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 TestTrait | |
{ | |
private $foo; | |
protected function upFoo() | |
{ | |
$this->foo++; | |
return $this->foo; | |
} | |
} | |
class TestClass | |
{ | |
use TestTrait; | |
public function example() | |
{ | |
$bar = $this->upFoo(); | |
print "bar is $bar\n"; | |
} | |
} | |
class TestExtended extends TestClass | |
{ | |
public function otherExample() | |
{ | |
$baz = $this->upFoo(); | |
print "baz is $baz\n"; | |
} | |
} | |
$test = new TestClass(); | |
$test->example(); | |
$test2 = new TestExtended(); | |
$test2->example(); | |
$test2->otherExample(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment