Created
June 28, 2010 18:00
-
-
Save Mikulas/456155 to your computer and use it in GitHub Desktop.
Nette automatic getter calling demonstration
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 | |
/** | |
* Nette automatic getter calling demonstration | |
*/ | |
namespace Model; | |
class Test extends BaseModel | |
{ | |
private $private = 'a'; | |
protected $protected = 'b'; | |
public $public = 'c'; | |
public function test() | |
{ | |
$this->private; | |
$this->protected; | |
$this->public; | |
$this->getPrivate(); | |
$this->getProtected(); | |
$this->getPublic(); | |
} | |
public function getPrivate() | |
{ | |
echo __METHOD__ . ' called'; | |
return $this->private; | |
} | |
public function getProtected() | |
{ | |
echo __METHOD__ . ' called'; | |
return $this->protected; | |
} | |
public function getPublic() | |
{ | |
echo __METHOD__ . ' called'; | |
return $this->public; | |
} | |
} | |
class VisibilityTest extends BaseModel | |
{ | |
public function test() | |
{ | |
$test = new Test(); | |
$test->private; | |
$test->protected; | |
$test->public; | |
$test->getPrivate(); | |
$test->getProtected(); | |
$test->getPublic(); | |
} | |
} | |
$test = new \Model\Test(); | |
$test->test(); | |
$visibility = new \Model\VisibilityTest(); | |
$visibility->test(); | |
/* ------------- OUTPUT ------------- */ | |
string(29) "Model\Test::getPrivate called" | |
string(31) "Model\Test::getProtected called" | |
string(28) "Model\Test::getPublic called" | |
string(29) "Model\Test::getPrivate called" | |
string(31) "Model\Test::getProtected called" | |
string(28) "Model\Test::getPublic called" | |
string(29) "Model\Test::getPrivate called" | |
string(31) "Model\Test::getProtected called" | |
string(28) "Model\Test::getPublic called" | |
string(29) "Model\Test::getPrivate called" | |
string(31) "Model\Test::getProtected called" | |
string(29) "Model\Test::getPrivate called" | |
string(31) "Model\Test::getProtected called" | |
string(28) "Model\Test::getPublic called" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment