LoginSignup
5
3

More than 5 years have passed since last update.

privateメンバー変数へのアクセスの例

Posted at
<?php
class A {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function copyName(A $from) {
        $this->name = $from->name;
    }

    public function __toString()
    {
        return $this->name;
    }
}

$a1 = new A('test1');
$a2 = new A('test2');

echo $a1.PHP_EOL;

$a1->copyName($a2);

echo $a1.PHP_EOL;
5
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3