Skip to content

Instantly share code, notes, and snippets.

@netojoaobatista
Last active December 10, 2015 20:48
Show Gist options
  • Save netojoaobatista/4490321 to your computer and use it in GitHub Desktop.
Save netojoaobatista/4490321 to your computer and use it in GitHub Desktop.
<?php
namespace visibility;
class DerivedUser extends User
{
public static function changeProtectedName(User $user, $name)
{
$user->protectedName = $name;
}
}
<?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
}
}
<?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