What does the variable $this mean in PHP?

前端 未结 10 1617

I see the variable $this in PHP all the time and I have no idea what it\'s used for. I\'ve never personally used it.

Can someone tell me how the variab

10条回答
  •  太阳男子
    2020-11-22 05:42

    Lets see what happens if we won't use $this and try to have instance variables and constructor arguments with the same name with the following code snippet

    name;
    
    ?>
    

    It echos nothing but

    name = $name; // Using 'this' to access the student's name
        }
    };
    
    $tom = new Student('Tom');
    echo $tom->name;
    
    ?>
    

    this echoes 'Tom'

提交回复
热议问题