LoginSignup
0
0

More than 5 years have passed since last update.

Static変数を$thisでアクセスしようとしたら__SETに引っかかった

Last updated at Posted at 2016-11-24

以下コードのようなことをしていた

<?php

trait test {
    public static $test;
}

/**
*
*/
class tester
{
    use test;

    public function __set($name, $val) {
        var_dump($name);//hoge
        $this->$name = $val;
    }

    function __construct($val)
    {
        $this->test = $val;

        return $this;
    }

    public function dumpTest()
    {
        echo $this->test;
    }
}

(new tester('hoge'))->dumpTest();

staticプロパティに$thisからアクセスしたことでエラーが発生するが,
これに__Setが反応する。

0
0
2

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
0
0