Last active
December 10, 2015 20:48
-
-
Save netojoaobatista/4490321 to your computer and use it in GitHub Desktop.
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 | |
namespace visibility; | |
class DerivedUser extends User | |
{ | |
public static function changeProtectedName(User $user, $name) | |
{ | |
$user->protectedName = $name; | |
} | |
} |
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 | |
namespace visibility; | |
class Sample { | |
public static function main() | |
{ | |
$user = new User(); | |
User::changePrivateName($user, 'João Batista Neto'); | |
DerivedUser::changeProtectedName($user, 'João Batista Neto'); | |
$user->showPrivateName(); //João Batista Neto | |
$user->showProtectedName(); //João Batista Neto | |
} | |
} |
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 | |
namespace visibility; | |
class User | |
{ | |
private $privateName; | |
protected $protectedName; | |
public static function changePrivateName(User $user, $name) | |
{ | |
$user->privateName = $name; | |
} | |
public function showPrivateName() | |
{ | |
echo $this->privateName, PHP_EOL; | |
} | |
public function showProtectedName() | |
{ | |
echo $this->protectedName, PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment