Skip to content

Instantly share code, notes, and snippets.

@greg-1-anderson
Created October 4, 2019 03:33
Show Gist options
  • Save greg-1-anderson/c249e18a04c53502294795ad7326f68d to your computer and use it in GitHub Desktop.
Save greg-1-anderson/c249e18a04c53502294795ad7326f68d to your computer and use it in GitHub Desktop.
Example of trait with private
<?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